A_Jump
state A_Jump (int chance, int offset, ...)
state A_Jump (int chance, str "state", ...)
Note: Jump functions perform differently inside of anonymous functions. |
Usage
Randomly advances to different frame. The chance value can range between 0 and 256. A chance of 0 will never jump, while a chance of 256 will always jump. If the jump does not happen, then the frame or instruction immediately following the A_Jump will be used as if A_Jump had not been present. If more than one offset or state values are present, A_Jump will choose one of them at random.
Note that offset specifies the number of frames to skip over, and not the number of lines. Instructions like goto, loop and stop cannot be jumped to directly for this reason. (If you need the A_Jump command to skip directly to an instruction, see the last example below for a way to do this.)
Jumps made with A_Jump are virtual, i.e. if the execution pointer is currently in the state of a base class of an actor, it will jump to the redefined state (if exists) of the derived actor. This is in contrast to the goto keyword which is static and execution does not leave the base class.
Note: Because of a limitation in the decorate code parser, you cannot use A_Jump on a single line if it has more than one state while using offset to specify the state to jump to. You will either need to split the states onto multiple lines and add an A_Jump to each line individually, or reference an actual state label like "See", "Melee", etc to make it work properly.
Examples
The following examples are the old method of jumping without states. They are still usable but it is strongly recommended that you use state labels for convenience.
POSS A 0 A_Jump (256, 2) POSS A 5 POSS A 5 // <- Jumps to this one (always) POSS A 5
POSS A 0 A_Jump (127, 4) POSS ABC 5 POSS D 5 // <- Jumps to this one (%50 chance) POSS E 3
POSS A 0 A_Jump (5, 1) goto Melee // <- This line is skipped because it does not define a frame POSS A 5 // <- Jumps to this one (Very little chance) POSS B 3
POSS A 0 A_Jump (127, 2, 3, 6) POSS A 5 // <-- Has a 50% chance of dropping through to here (no jump), otherwise... goto Death POSS B 6 // <-- Jumps here... goto See POSS BCD 5 // <-- Or here... goto Death POSS E -1 // <-- Or here, with equal probability.
These examples use state labels. As you can see from both methods, state labels are a much simpler way of doing jumps.
POSS A 0 A_Jump (127, "Pain") POSS ABC 3 Stop Pain: // <-- 50% chance to jump to this state POSS G 3 POSS G 3 A_Pain // Play pain sound loop
POSS A 0 A_Jump (256, "Boogie", "Gasp", "Death") // <-- Always jumps to either... Stop Boogie: // <-- This state... POSS ABCD 4 loop Gasp: // <-- This state... POSS E 15 Goto See Death: // <-- Or this state at an equal chance. POSS H 5 POSS I 5 A_Scream POSS J 5 A_NoBlocking POSS K 5 POSS L -1 stop
Here is a real example of where jumping to different states would be useful. This is a custom made DECORATE version of Korax's attack pattern using state jumps.
Missile: KORX E 8 Bright A_FaceTarget KORX E 0 A_PlaySound("KoraxAttack") TNT1 A 0 A_Jump(256, "Wraith", "DemonFX1", "DemonFX2", "FireDemon", "Centaur", "Serpent") Goto See Serpent: KORX A 0 A_SpawnProjectile ("SerpentFX", 55, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("SerpentFX", 55, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("SerpentFX", 82, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("SerpentFX", 82, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("SerpentFX", 110, -35, 0, 4, 0) KORX F 8 A_SpawnProjectile ("SerpentFX", 110, 35, 0, 4, 0) KORX E 5 Bright Goto See Wraith: KORX A 0 A_SpawnProjectile ("WraithFX1", 55, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("WraithFX1", 55, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("WraithFX1", 82, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("WraithFX1", 82, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("WraithFX1", 110, -35, 0, 4, 0) KORX F 8 A_SpawnProjectile ("WraithFX1", 110, 35, 0, 4, 0) KORX E 5 Bright Goto See DemonFX1: KORX A 0 A_SpawnProjectile ("Demon1FX1", 55, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon1FX1", 55, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon1FX1", 82, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon1FX1", 82, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon1FX1", 110, -35, 0, 4, 0) KORX F 8 A_SpawnProjectile ("Demon1FX1", 110, 35, 0, 4, 0) KORX E 5 Bright Goto See DemonFX2: KORX A 0 A_SpawnProjectile ("Demon2FX1", 55, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon2FX1", 55, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon2FX1", 82, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon2FX1", 82, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("Demon2FX1", 110, -35, 0, 4, 0) KORX F 8 A_SpawnProjectile ("Demon2FX1", 110, 35, 0, 4, 0) KORX E 5 Bright Goto See FireDemon: KORX A 0 A_SpawnProjectile ("FireDemonMissile", 55, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("FireDemonMissile", 55, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("FireDemonMissile", 82, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("FireDemonMissile", 82, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("FireDemonMissile", 110, -35, 0, 4, 0) KORX F 8 A_SpawnProjectile ("FireDemonMissile", 110, 35, 0, 4, 0) KORX E 5 Bright Goto See Centaur: KORX A 0 A_SpawnProjectile ("CentaurFX", 55, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("CentaurFX", 55, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("CentaurFX", 82, -52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("CentaurFX", 82, 52, 0, 4, 0) KORX A 0 A_SpawnProjectile ("CentaurFX", 110, -35, 0, 4, 0) KORX F 8 A_SpawnProjectile ("CentaurFX", 110, 35, 0, 4, 0) KORX E 5 Bright Goto See