A_CheckRandom

From SRB2 Wiki
Jump to navigation Jump to search

A_CheckRandom is an action that determines by chance whether to call a specified state or not. Var1's lower 16 bits determine the denominator of the chance of calling the state, while Var1's upper 16 bits determine the numerator – i.e.: the chance of the state being called is (Var1 upper 16 bits) ÷ (Var1 lower 16 bits). If Var's upper 16 bits are zero, the numerator defaults to 1 – i.e.: the chance of the state called is instead 1 ÷ (Var1 lower 16 bits). For example, a Var1 value of 3 would give a 1/3 chance of calling the state, while a Var1 value of (2<<16)+3 would give a 2/3 chance of calling the state.

Note that neither the numerator or denominator should be set to 0, as in both cases the state will never be called by this action. The former case's result is because the numerator being 0 would always give a 0% chance of the state being called; while the latter case's result is because division by 0 is undefined and would crash the game if attempted, so the action cancels itself to prevent this happening. Otherwise, the numerator should not be equal to or higher than the denominator; this will cause the state to be called 100% of the time this action is called.

Var2 determines the state to call when this action is successful; see List of states for a full list. In SRB2, this action is used by Brak Eggman's electric barrier to give a 1/10 chance of the barrier creating a random spark as it starts to reappear around the boss, recalculated every tic for 5 seconds before the shield fully returns.

This action originates from the v2.0 modification SRB2Morphed and was added to SRB2 itself in v2.1.

  Actions – Checking [view]
A_BubbleCheckA_CheckAmbushA_CheckHealthA_CheckHeightA_CheckRandomA_CheckRangeA_CheckRingsA_CheckTargetRingsA_CheckThingCountA_CheckTotalRingsA_CheckTrueRangeA_ChickenCheckA_LookA_SearchForPlayers