-
Notifications
You must be signed in to change notification settings - Fork 0
var
Kiki edited this page Dec 25, 2024
·
11 revisions
The var
keyword in Scriptor is optional when declaring a script variable.
Using var offers additional safeguards, such as raising an error if the variable has already been declared in the script. This helps improve code safety by preventing accidental overwrites.
However, it 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
Valid Example:
var mystruct = {}
mystruct.x = 255
mystruct.y = 200
Back to Repo ● Wiki Home
Copyright © coldrock.games