Headcannon Game Engine Script Commands - Switch
Index:
Nonsequential Values:
(D) (E) | _Switch(Reg) |
(D) (E) | _Switch(Chr) |
(D) (E) | _Switch(Obj) |
(D) (E) | _Case |
(D) (E) | _DefaultCase |
(D) (E) | _BreakCase |
(D) (E) | _EndSwitch |
Sequential Values:
(D) (E) | _StateSwitch(Reg) |
(D) (E) | _StateSwitch(Chr) |
(D) (E) | _StateSwitch(Obj) |
Descriptions:
Nonsequential Values:
_Switch(Reg)
_Switch(Chr)
_Switch(Obj)
(ALL) (Example)
"Switch" conditions test for specific values based on a list of "Case"s that specify what to
do if the value of the tested variable is equal to any one value in the list. The "Switch" groups "Case"
tests together, and must be ended by an "EndSwitch"
The "Switch" tests the value of the
given variable against the value presented in each "Case" one by one, and if it does not
match, no Commands inside those "Case"s are processed. If the variable's value matches the
value of a "Case", the Commands beginning at that "Case" are processed until a "BreakCase" is met,
and the Function skips to the corresponding "EndSwitch" Command. If no match is found,
but the "DefaultCase" Command is used, the Commands beginning at the "DefaultCase" will
be processed.
"Switch" conditions may be "nested"; any "Case" within one "Switch" may contain another "Switch"/"Case"/"BreakCase"/"DefaultCase"/"EndSwitch" set
"Switch" is slower than "StateSwitch", but allows for the use of non-sequential values
Parameters:
- Var ID
The ID number of the variable to test against each of the following "Case"s
In the case of "Registers", "Var ID" is the ID of the "Register" to test. The "U" tag may be used
to specify a user-defined Register. Otherwise, the ID will refer to a Game Register
In the case of Player Variables, the Player whose variable should be tested must be Fetched to Reference 0, and "Var ID" is the ID of the Player Variable to test. The capital "A"
tag may be used to specify an "Active" variable, the lower-case "a" to specify a user-
defined "Active" variable, and the lower-case "c" to specify a user-defined Constant.
Otherwise, the ID will refer to one of the Player's required Constants
In the case of Object Variables, the Object whose variable should be tested must be Fetched to Reference 0, and "Var ID" is the ID of the Object Variable to test. The "E" tag may
be used to specify an "Extra" variable. Otherwise, the ID will refer to one of the
Object's standard variables
_Case
(ALL) (Example)
"Case" tests must appear inside a "Switch" condition. They define a value to test against
the variable specified by one of the "Switch" condition Commands, and mark the beginning of
the Commands to process if the two values are equal. If the value of the specified variable
is equal to the value of the given "Case", all Commands following that "Case" will be processed until a
"BreakCase" or EndSwitch is reached
This means that if there is no "BreakCase" Command before
the next "Case" Command, the Commands listed for the next "Case" will also be processed,
which can be useful if two or more values should cause the same series of Commands to run
"Case"s can be listed in any order, regardless of their values. "Case"s whose values are most
likely to be true should generally be listed first to reduce the amount of time that is spent testing
Parameters:
_DefaultCase
(ALL) (Example)
"DefaultCase" functions similarly to "Case", except that it is processed if no other "Case"s
are satisfied. "DefaultCase" is optional, but useful if certain operations should only be
performed if none of the "Case"s are satisfied.
Parameters:
None
_BreakCase
(ALL) (Example)
"BreakCase" marks the end of a series of Commands to process if a "Case" test is proven
true. If a "BreakCase" is reached, the Function will jump to the "EndSwitch"
that corresponds with the current "Switch" condition.
The "BreakCase" Command is optional, in that if it is omitted for a "Case", the Commands within any following "Case"
will also be processed, until a "BreakCase" or "EndSwitch" is reached
Parameters:
None
_EndSwitch
(ALL) (Example)
"EndSwitch" marks the end of a "Switch" condition. This is the point to which the Function
jumps after a "Case" test that has been proven true reaches it's "BreakCase", if there is
one.
The "EndSwitch" Command is mandatory; a "Switch" condition must end with an "EndSwitch"
to separate its contents from the rest of the Function, and to allow proper nesting of
"Switch" conditions within each other when necessary
Parameters:
None
Sequential Values:
_StateSwitch(Reg)
_StateSwitch(Chr)
_StateSwitch(Obj)
(ALL) (Example)
"StateSwitch" obtains the value of a variable, and uses it as an index into a list of jump locations to move to a different part of the
Function based on that value
"StateSwitch" is faster than "Switch", but requires a full list of jump locations for
all values between 0 and the greatest possible value that will ever be assigned to the variable. If the variable
stores values in constant multiples (such as a variable that only reads 0, 2, 4, 6...), the value can be copied
and divided by the constant (in the example, divide by 2 and the variable's values will become 0, 1, 2, 3...) to
cut down on list size by using sequential values. If the values are large and/or erratic, it might be best to use "Switch" instead
To break out of a section of code referenced by the jump list and avoid code meant for other "States", use the "GoTo"
Command
Parameters:
- Var ID
The ID number of the variable whose value should be used as an index into the jump list
In the case of "Registers", "Var ID" is the ID of the "Register" to test. The "U" tag may be used
to specify a user-defined Register. Otherwise, the ID will refer to a Game Register
In the case of Player Variables, the Player whose variable should be tested must be Fetched to Reference 0, and "Var ID" is the ID of the Player Variable to test. The capital "A"
tag may be used to specify an "Active" variable, the lower-case "a" to specify a user-
defined "Active" variable, and the lower-case "c" to specify a user-defined Constant.
Otherwise, the ID will refer to one of the Player's required Constants
In the case of Object Variables, the Object whose variable should be tested must be Fetched to Reference 0, and "Var ID" is the ID of the Object Variable to test. The "E" tag may
be used to specify an "Extra" variable. Otherwise, the ID will refer to one of the
Object's standard variables
- Num of States
The size of the jump list, in number of entries. This value should be equal to the greatest value that will ever be assigned to the variable that is being tested, and should correspond exactly with the number of jump locations that are listed immediately below:
- Jump Location
These are the locations to jump to within the Function when the variable contains a value equal to this entry's position in the list. The first entry is the jump location for a value of 0, the second is the jump location for a value of 1, the third for a value of 2, etc.
There are three ways to represent the jump location:
- Exact Location- Start at the beginning of the Function and count the number of Commands that come before the first one that should be run for this "State", but do not count their Parameters. Enter that exact value (the first Command in the Function would be "0", the second "1", etc.)
- Relative Location- Count the distance between the "StateSwitch" Command and the first Command that should be run for this "State" (in number of Commands, do not the Parameters). Enter that value, prefixed with either a "+" or "-" to denote the direction of the jump. (The Command immideately after the "StateSwitch" would be "+1", the Command immediately before the "StateSwitch" would be "-1")
- Label- Enter the name of the Label to jump to, prefixed by an "@" symbol (To jump to the location of the label named "State2", use "@State2"
Examples:
Nonsequential Values:
This section lists examples of complete sets of "Switch"/"Case"/"BreakCase"/"Default"/"EndSwitch" Commands, because they have no individual use
_Switch(Reg)
_Switch(Chr)
_Switch(Obj)
(Description)
_Case
(Description)
_DefaultCase
(Description)
_BreakCase
(Description)
_EndSwitch
(Description)
#_Switch(Obj)
: E1 ;"Extra Variable" 1 of the Object "Fetched" to Reference 0
#_Case
: 15
#_Case
: 16
;***
;Code here is processed only when the value is 15 or 16
;***
#_BreakCase
#_Case
: 0
;***
;Code here is processed only when the value is 0
;***
#_BreakCase
#_DefaultCase
;***
;Code here is processed only when the value is anything other than 0, 15, or 16
;***
#_EndSwitch
; ----------
#_Switch(Chr)
: a3 ;User-created "Active Variable" 3 of the Player "Fetched" to Reference 0
#_Case
: 10
;***
;Code here is processed only when the value is 10
;***
#_Switch ;For Player Variable value of 10, do something different based on User Register 0
: U0 ;User Register 0
#_Case
: 32
;***
;Code here is processed only when the value is 32
;***
#_BreakCase
#_Case
: 8
;***
;Code here is processed only when the value is 8
;***
#_BreakCase
#_Case
: 1
;***
;Code here is processed only when the value is 1
;***
;***
;Without a "DefaultCase", nothing happens if the value is anything other than 32, 8, or 1
;***
#_EndSwitch ;This ends the "Switch(Reg)"
#_BreakCase ;This ends case "10" for the "Switch(Chr)"
#_Case
: 7
;***
;Code here is processed only when the value is 7
;***
#_Case
: 14
#_Case
: 19
;***
;Code here is processed only when the value is 7, 14, or 19
;***
#_BreakCase
#_DefaultCase
;***
;Code here is processed only when the value is anything other than 10, 7, 14, or 19
;***
#_EndSwitch
Sequential Values:
_StateSwitch(Reg)
_StateSwitch(Chr)
_StateSwitch(Obj)
(Description)
#_StateSwitch(Chr)
: a54 ;(Chr0) User-created "Active Variable" 54 of the Player "Fetched" to Reference 0
: 4 ;There are 4 possible "States"
: @2 ;(State 0)
: @3 ;(State 1)
: @4 ;(State 2)
: @5 ;(State 3)
@2
;***
; Code here is processed when the value is 0
;***
#_GoTo ;Skip past other "States" code
: @6
@3
;***
; Code here is processed when the value is 1
;***
#_GoTo ;Skip past other "States" code
: @6
@4
;***
; Code here is processed when the value is 2
;***
#_GoTo ;Skip past other "States" code
: @6
@5
;***
; Code here is processed when the value is 3
;***
@6
;***
; Code to continue running after the State-Specific code is processed
;***
; ----------
#_StateSwitch(Reg)
: U13 ;(Reg) User Register 0
: 5 ;There are 5 possible "States"
: @7 ;(State 0)
: @8 ;(State 1)
: @9 ;(State 2)
: @9 ;(State 3)
: @10 ;(State 4)
@7
;***
; Code here is processed when the value is 0
;***
@8
;***
; Code here is processed when the value is 0 or 1
;***
#_GoTo ;Skip past other "States" code
: @11
@9
;***
; Code here is processed when the value is 2 or 3
;***
#_GoTo ;Skip past other "States" code
: @11
@10
;***
; Code here is processed when the value is 4
;***
@11
;***
; Code to continue running after the State-Specific code is processed
;***