Skip to main content

Modes and Switches

Modes and switches are both boolean values, with modes being constants, and switches being variables. Of course, their usage comes about when conditionals are involved.

Why modes and switches?

They're both to control the flow of the program in an easy-to-understand way. You can take advantage of them through conditionals, or you can choose to ignore them.

The idea is that modes are supposed to control the bigger picture flow of the program when taken advantage of, whereas switches are for more minute details. As such, many switches can be on, and only one mode can be on.

You get to set the mode and which switches you want to be on when compiling, from the list of them you declare in the MODES and SWITCHES sections respectively. This allows you to take the program in different directions when you need to, with some input ahead of time.

By default, no switches exist, whereas a mode called $DEFAULT exists, and is set to true.

How to declare modes and switches

You declare them in the appropriate sections, MODES, and SWITCHES. Here's a simple example for reference:

<MODES> # For declaring modes #
# Example of set of modes, based on speed #
$SLOW
$MEDIUM
$FAST

<SWITCHES> # For declaring switches #
# Example of set of switches, based on tasks to do #
$DO_1
$DO_2
$DO_3

Their values are then set when compiling the script with the options you give.

How to use modes and switches

You can simply use conditionals to take advantage of them. Here's an example:

<MODES> # For declaring modes #
# Example of set of modes, based on speed #
$SLOW
$MEDIUM
$FAST


<SWITCHES> # For declaring switches #
# Example of set of switches, based on tasks to do #
$DO_1
$DO_2
$DO_3


<MACRO>
@if $SLOW { # Set `delays` to be very slow #
@delay [500,500]
}
@elseif $MEDIUM | $DEFAULT { # If it's default we treat it as if it is medium #
@delay [100,100]
}
@else { # Set it to be very fast, as $FAST is on
@delay [10,10]
}

# Press the number corresponding to the switch
@if $DO_1 {
1
}
@if $DO_2 {
2
}
@if $DO_3 {
3
}

For more info on conditionals, check the page for it out.

How to update switches

Due to the nature of modes, you cannot update them, they are only set when compiling it and are more absolute.

As for switches, you can use the builtin setter function @setBool to update them. You can also use it to add new switches later on, but you won't be able to set them when compiling.

The boolean values used with @setBool are TRUE, and FALSE. Here's an example:

<SWITCHES>
$DO_x

<MACRO>
@setBool [$DO_x, FALSE]

Check out the next section on builtin functions to understand setters and conditionals better.