-
-
Notifications
You must be signed in to change notification settings - Fork 9
Global Variables
IsaacShelton edited this page Mar 21, 2022
·
1 revision
Global variables are variables that persist for the entire duration of the program.
Global variables are declared using an identifier followed by a type while in the global scope.
my_global_variable Type
Global variables can be given an initial value, which will be assigned at the beginning of the program.
target_fps int = 60
By default, global variables are zero-initialized. If this behavior is undesired, you can set the initial value to undef
in order to leave the memory uninitialized
not_used_yet double = undef
Global variables that have a __defer__
will have it called when the program terminates.
Global variables that are marked as POD
(plain-old-data), are immune to __defer__
management procedures.
manual_string POD String = "Hello World"
See POD variables for more information.
import basics
custom_greeting String = "Hi "
func main {
greet("Isaac")
custom_greeting = "Hello "
greet("Ryan")
custom_greeting = "Welcome "
greet("John")
}
func greet(name String) {
print(custom_greeting + name)
}