Skip to content

Global Variables

IsaacShelton edited this page Mar 21, 2022 · 1 revision

Global Variables

Global variables are variables that persist for the entire duration of the program.

Declaration

Global variables are declared using an identifier followed by a type while in the global scope.

my_global_variable Type

Initial Value

Global variables can be given an initial value, which will be assigned at the beginning of the program.

target_fps int = 60

Disabling Zero-Initialization

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

Deference

Global variables that have a __defer__ will have it called when the program terminates.

POD Global Variables

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.

Usage Example

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)
}
Clone this wiki locally