Switch¶
A switch that can be turned on or off offering a wide variety of actuation flow such as starting an event, changing other hit values, offer a toggling feature and be only actuable using Kabbu's horn. Consult the switch actuation section for more details.
Data Arrays¶
data[0]: Controls the actuation flow, see the section below for detailsdata[1]: Controls the actuation flow, see the section below for detailsdata[2]: Ifdata[1]is 0, this the the amount of frames that must pass after an actuation for the switch to automatically turn itself off. This is optional, this feature isn't used when it doesn't exist or is negative. As a side effect of enabling this feature, thehitvalue is continuously set to true if theactivationflagflag slot is truedata[3]: UNUSED (The value is used in an if statement in Update, but the if leads to no code)data[4]: If it's 1, the entity'srotatertag is set toHornable(allows PlayerControl to get a green ! emoticon when getting 2.5 or lower distance from the switch for 5 frames) and disallows the switch to be actuated using Leif's Icicle or Vi's beemerang. This is optional, no change happens if it's 0 or not present. NOTE: anything other than 0 or 1 is considered invalid and will prevent the switch from being actuated under any circumstances
Additional data¶
boxcol: Required to be present with valid dataregaionalflag: If positive, a regionalflag slot, see the table below for detailsactivationflag: If above 0, a flag slot, see the table below for details
About switch actuation¶
The meaning of data[0] and data[1] these 2 data elements have very complex semantics. They together control the flow of the actuation of the switch which is stored in the hit value as well as how the activationflag and regionalflag slots are used.
data[1] being 0 allows data[2] to function if it exists and is positive which the table will mention when it is applicable. The implications of this when applicable are outlined in the table below.
To note, data[4] acts completely independently of data[0] and data[1]. It only permits actuation from Kabbu's horn and makes the switch Hornable which allows PlayerControl to get a green ! emoticon when getting 2.5 or lower distance from the switch for 5 frames.
Unless stated otheriwse, activationflag and regionalflag only applies when the former is above 0 and when the latter is positive. Here is a breakdown of all actuation flow:
data[0] |
data[1] |
Starting hit value |
Actuation flow | Effects on actuation |
|---|---|---|---|---|
| 0 | 0 | If the activationflag flag slot (with the 0 value being allowed) is true, the switch will continuously set its hit to true during Update if data[2] exists and isn't negative. |
This switch can only be toggled on. If data[2] exists and is positive, the switch automatically turns itself off after the amount of frames contained in data[2] passed. Otherwise, the switch cannot be turned off |
When hit turns true, both activationflag and regionalflag respective slots are set to true |
| 0 | 1 | activationflag (with the 0 value allowed) tells the starting value of hit by its flag slot. |
The switch can be toggled on and off. Once toggled, there is a 30 frames cooldown before being able to toggle it again, but data[2] can override the cooldown time if it exist and isn't negative |
When actuated, the activationflag flag slot is set to the new hit value. Additionally, all other switch NPCControl present with the same data[0], data[1] and activationflag values will have their hit values set to the new one after the toggle.1 |
| 1 | Negative | false | The switch can only be turned on once unless the TOG modifier is active which allows the switch to be toggled on and off. |
When the switch is actuated, both activationflag and regionalflag respective slots are set to true. Additionally, if entity.originalid has an undefined (-1) animid, entity.iskill is set to true and if it's WoodenSwitch, the moveobj angles are set to (0.0, -60.0, 0.0) (This moves the lever stick) |
| 1 | 0 or above | false2 | The same actuation flow than if data[1] was negative3 |
That same effects occurs than if data[1] was negative with the addition that data[1] is an event id that will trigger with this switch as the caller each time the switch is actuated |
1: This combination is practically unused under normal gameplay as it is likely an older implementation of event 169
2: If data[1] is 1, the starting value of hit is the value of the activationflag (0 included) flag slot
3: If data[1] is 0, it allows data[2] if it exists and isn't negative to make the switch automatically turns itself off after the amount of frames contained in data[2] passed after each actuation. It also sets the hit value to true continuously during Update if activationflag (0 included) flag slot is true
Setup¶
- entity.
rigidgets effectively fixed by placing it in kinematic mode without gravity and all constraints frozen - entity.
alwaysactiveis set to true nointeractis set to true- if the
activationflagflags slot is true,hitis also set to true. - From there some adjustements happens based on the
originalid's AnimID(nothing happens if it doesn't match any of them):SwitchCrystalandBigCrystalSwitch: A GlowTrigger is added to the entity.model's first child with itsparentset to this object and theglowpartsset to a single element corresponding to the MeshRender already attached to the firstmodelchild.WoodenSwitchandSteelSwitch:internaldatais initialised to a single element being -60 if it's aWoodenSwitchor -100 if it's aSteelSwitch, Then, themoveobjis set to the entity'smodelfirst child and ifhitwas set to true earlier, its angles are set to (0.0,internaldata[0], 0.0)
- If the player is present, all collision between the
boxcoland the player's wall detector are ignored. - If the
originalidis not amongBigCrystalSwitch,WoodenSwitchorSteelSwitch, AddPushder is called. - If
data[4]is 1 the entity'srotatertag gets set toHornable(allows PlayerControl to get a green ! emoticon when getting 2.5 or lower distance from the switch for 5 frames).
Update¶
What happens at the start depends on data[1] and data[2].
If data[1] is 0 and data[2] is present and not negative:
- If the
actioncooldownhasn't expired, it is decremented by the game's frametime. Otherwise, if theactioncooldownexpired on the last update cycle (checked by being above -1000.0),hitis set to false andactioncooldownis set to -1100.0 so it doesn't perform this logic on further updates (this is the autooff feature taking effect) - If the
activationflagisn't negative and the flag slot of it is true,hitis set to true.
Otherwise, if data[1] is 1 and the actioncooldown hasn't expired yet, it is decremented by the game's frametime.
In all cases, if the entity.originalid is the WoodenSwitch or SteelSwitch AnimID, the moveobj's y angle is set to a LerpAngle from the existing one to 0.0 if hit is false or internaldata[0] (-60.0 for a WoodenSwitch or -100.0 for a SteelSwitch) if it's true with a factor of a 1/10 of the game's frametime.
OnTriggerEnter¶
Nothing happens if any of the following is true:
- We are in a
pauseorminipause - message is grabbed
collisionammountis higher than 1 (this is a debounce protection)- The other gameObject tag isn't
BeetleHorn,BeetleDash,IcefallandIceclewhile it's not the playerbeemerang data[4]is not present or it is and its value is 1 while the other gameObject tag isBeetleHornorBeetleDash(This basically enforces thatdata[4]being 1 means that only Kabbu's horn can actuate the switch)
The following occurs:
collisionammountis incremented- A HitPart particle is played at this position + (0.0, 0.5, 0.0)
- The main logic section occurs, see below for details
- If the other gameObject was the player
beemerang, itshitis set to true and theWoodHitsound is played on the entity - If the entity
originalidisn't -1 (None), SwitchSound is called indicating a press
What happens in the main logic depends on data[0].
data[0] is 1¶
This does nothing if hit is true and the TOG modifier is not active:
- If
data[1]isn't negative, the event at its id is started which this being the caller. Otherwise, the regionalflag slot atregionalflagsand the flag slot atactivationflagare set to true hitis set to true unless theTOGmodifier is active in which case, the value is toggled instead- If the entity
originalidis -1 (None), itsiskillis set to true - If the entity
originalidis theWoodenSwitchanimid, themoveobjangles are set to (0.0, -60.0, 0.0)
data[0] is 0¶
This depends on data[1]. If it's not 1, then hit is set to true and the regionalflag slot at regionalflags and the flag slot at activationflag are set to true. If it's 1 and the actioncooldown expired:
hitis toggledactioncooldownis set to 30.0- If the
activationflagisn't negative, the corresponding flag slot is set tohit - For each
Switchin the map excluding this object, if itsdata[0]is 0, itsdata[1]is 1 and itsactivationflagisn't negative and matches this object's, itshitis set to this objecthit
Common end¶
Finally, no matter which branch applied, if data[2] exists and it's negative, actioncooldown is set to it.
Hazards.OnObjectStay¶
If the NPCControl passed has this type, it returns true which allows it to stay in collision with the Hazards.