Variable declarations
Variable declarations allow you to specify a variable's networking priority and its initial value. They aren't required — you can use a variable straightaway, without declaring it — but because Megalo's default variable networking priority can't survive host migrations, you'll probably want to use them.
Variable declarations look like this:
declare SOME_VARIABLE declare SOME_VARIABLE = SOME_NUMBER declare SOME_VARIABLE with network priority SOME_PRIORITY declare SOME_VARIABLE with network priority SOME_PRIORITY = SOME_NUMBER
When specifying the variable to declare, you are allowed to use an alias.
Only number and timer variables can be given initial values. These values can be any number except for another variable. If you do not specify an initial value (or if you don't declare the variable at all), then the initial value used is zero.
All variable types except for timers can have a networking priority set. The network priority values are:
- default
- The meaning of this value is unclear. Testing has established that a variable's value will be lost after a host migration if its network priority was the default.
- low
- Testing has established that low-priority variables can survive a host migration.
- high
- Testing has established that high-priority variables can survive a host migration. If you wish to display a player variable in the UI, it must be high-priority.
- local
- Variables with this network priority aren't sent over the network at all.
Declaring a variable multiple times generates a compiler warning if the declarations don't conflict with each other or contain redundant information (e.g. multiple initial values), or a compiler error otherwise.