-
Notifications
You must be signed in to change notification settings - Fork 0
var
The var keyword in Scriptor is optional when declaring a script variable but it offers advantages:
-
You receive an error, if a variable with the specified name does already exist, so unintentionally overwriting existing variables can not happen.
-
Auto-Cleanup. A variable declared with the
varkeyword will be removed from the script at the end.
Keep in mind, that scriptor preserves variables between runs. This is important for callbacks which will be launched sometimes many frames after the main code of the script. Variables declared withvarwill automatically vanish. -
Using the
varkeyword has no performance impact at runtime.
var <variable_name> = [value|expression|initializer]
- Declaration with a value:
var myvar = 25 - Declaration with an expression:
var myvar = self.x + self.sprite_width / 2 - Declaration with an array initializer:
var myvar = [] - Declaration with a struct initializer:
var myvar = {} You can assign values to an array directly during initialization.
Examples:
var myarray = [1,2,3,4]
var myarray = ["Hello", "World", self.text]Unlike arrays, you cannot initialize struct members directly during declaration.
Invalid Example:
var mystruct = { x:255, y:200 } // This is an error (not in GML, but in scriptor)Valid Example:
var mystruct = {}
mystruct.x = 255
mystruct.y = 200Back to Repo ● Wiki Home
Copyright © coldrock.games
- Home
- Scriptor Contents
- Scriptor Configuration
- Notepad⁺⁺ Integration
- Create a Script
- $ Variables
- Call a GML Function
- Scriptor global functions
- #-Commands
- The Scriptor Broker
- Broker Events
- Self-Registering Scripts
- Registering Broker Events
- Scriptor Broker File Format
- Extending Scriptor
- var
- new
- goto
- gosub and return
- return (without gosub)
- call
- reset
- Loops
- Conditionals