This is an old revision of the document!
⇐ Index
4rpl supports special syntax for referencing global variables, vectors, lists, and tables.
<-* ->* -?* –* <-!* ->!* -?!* –!*
All of the variable commands can also be used followed by a * symbol in order to access global variables instead. Global variables do not belong to one single script, reading or writing to a global variable will modify the same exact value from any script.
Global variables may have the same names as local variables, there is no interference between them.
One example global variables may be used for is storing values which should always be the same across all units. That way it isn't necessary to send a message to each individual unit.
# --SomeScript-- true ->*disableMyCustomUnits
# --CustomUnit-- if (<-*disableMyCustomUnits) SetUnitDebugText(self "Disabled") else SetUnitDebugText(self "") @Operate endif
⇐ Index
Vectors contain up to 4 fields. These fields can be referenced with a suffix that infers the use of the vector
Simply place the suffix after the variable name for reading or writing. Suffixes are fungible.
Lists are collections of data. They are similar to arrays but they do not have a fixed length.
They can have items added or removed. The elements in a list can be referenced using specific APIS,
like GetListElement (and other List APIs).
They can also be accessed using square bracket notation [<-index]
, which is a compact way of writing
list-element getters/setters.
[<-index]
can be written on its own and will translate to <-index GetListElementRPL
,
effectively getting the element at the given index from a list at the top of the stack.
If the item on the stack is no list an error will be printed to the console.
However, if [<-index]
is preceded by a variable setter, ->variable [<-index]
,
it along with the variable setter will translate to <-variable <-index SetListElementRPL
,
effectively setting element number “index” of the variable to whichever value is on top of the stack.
If variable is not a list, a warning will be printed to the console.
Tables are collection of named data. They are sometimes called dictionaries in other languages.
They contain data made up of a string name (the key) and a value. A value can be quickly looked up by its
name/key.
Data in a table can be referenced with GetTableElement (and other
Table APIs).
Data can also be accessed using curly brace syntax {<-key}
, which is a compact way of writing
table-element getters/setters.
{<-key}
can be written on its own and will translate to <-key GetTableElementRPL
, effectively getting
the element at the given key from a table at the top of the stack. If the item on the stack is not a table,
an error will be printed to the console.
However, if {<-key}
is preceded by a variable setter, ->variable {<-key}
, it along with the
variable setter will translate to <-variable <-key SetTableElementRPL
, effectively setting the value of
that key in the variable to whichever value is on top of the stack. If variable is not a table,
a warning will be printed to the console.
CreateTable ->table 42 ->table{"SomeName"} traceallsp(<-table{"SomeName"})