-
Notifications
You must be signed in to change notification settings - Fork 0
Structs
Structs are a nice and tidy way to store data.
They can be declared by using struct
, followed by the ID/name of your structure. Every pixel that comes after that is a struct argument (or field, if you are familiar with OOP).
In this example we declare a struct identified by a blue pixel with two fields .
Once a struct is declared, we can initialize it and store it into a variable by just passing the struct name as the value of the variable:
Now the variable is linked to the struct we defined earlier, and all of its fields have their value set to 0
.
Fields in a struct variable can be accessed and updated by the use of the dot operator op.dot
which works just as a regular dot from most programming languages.
The following expression accesses the green field from the variable we had initialized before. If we printed out its content, it would print 0
, as previously said.
On the other hand, if you want to change a field's value, you can simply see the whole 'struct dot field ' expression as a single variable, so that you can use variable.set
on it:
Here the green field gets updated, so that its stored value is "A" .