Skip to content

0x02 — branch

Reads a branch word at SCR_DATA+0x0C. The high byte is a condition id. If nonzero, it reads the next 8 bytes as condition payload and calls CRadiScript::CheckCondition(unsigned char,unsigned long,const SCR_DATA*). If the condition passes, or if there is no condition id, it sign-extends the low 24 bits of the branch word as a relative word offset, writes the new cursor to SCR_DATA+0x0C, and returns 2.

proven— handler traced, and exercised by at least one shipped script.

At a glance

Opcode0x02 (2)
HandlerCRadiScript::Command_02
SignatureCRadiScript::Command_02(int,SCR_DATA*,unsigned int,unsigned int)
Translation unitr_script_run0.cpp
Address— debug build; click for all 3
Handler size0xB8 (184 bytes)
FamilyScript control, flags and values
Command size4 + extra_words * 4 bytes

Documented forms

This opcode is documented under more than one name, one per branch of the handler. They are the same opcode and the same handler; which branch runs is chosen by the argument byte or a control word.

FormEngine nameWhat it does
branch—Jumps to a label, unconditionally or when a condition holds.
if_flag—Jumps when a game flag matches. Written as a block, it runs the block instead of jumping.
if_value—Jumps when a script event value matches. Written as a block, it runs the block instead of jumping.
jump—Jumps to a label unconditionally.
unless_flag—Jumps when a game flag does not match - the opposite of if_flag.
unless_value—Jumps when a script event value does not match - the opposite of if_value.

Handler behaviour

Reads a branch word at SCR_DATA+0x0C. The high byte is a condition id. If nonzero, it reads the next 8 bytes as condition payload and calls CRadiScript::CheckCondition(unsigned char,unsigned long,const SCR_DATA*). If the condition passes, or if there is no condition id, it sign-extends the low 24 bits of the branch word as a relative word offset, writes the new cursor to SCR_DATA+0x0C, and returns 2.

Encoding

The command header is one 32-bit word, as described in §3 Instruction encoding:

 31            24 23            16 15             8 7              0
+----------------+----------------+----------------+----------------+
|  flags         |  argument byte |  extra words   |  0x02          |
+----------------+----------------+----------------+----------------+

Bits 8–15 give the number of 32-bit operand words that follow. Bits 16–23 are handed to the handler as a bitfield; on character commands bit 0 normally says whether a character selector word is present. Bit 31 is the keep-going bit.

Operand fields

41 documented fields. input fields are read from the command's operand words; derived fields are computed from other fields rather than stored separately.

FieldRoleMeaning
category_selectorinputSelects which category the handler acts on.
characterinputThe packed 32-bit character selector word. Its low half is the character id and byte 2 is a secondary class/variant input; see character_number and character_variant.
character_rawinputRaw field preserved verbatim; its meaning is not yet traced.
character_sourceinputWhere character is read from.
compare_controlinputBitmask controlling which optional compare values follow.
compare_from_eventinputWhether compare is read from an event value instead of being a literal on this line.
cond_baseinputLow 7 bits of condition: which condition is evaluated.
conditioninputCondition selector byte. The low 7 bits pick the condition (cond_base) and bit 7 inverts the result (invert). 0 means unconditional.
condition_argsinputThe condition's operand words, kept verbatim when no structured form applies.
condition_word1inputWord 1 of the packed condition entry.
countinputHow many entries this command carries.
event_valueinputScript event-value id that the condition or command reads.
expectedinputValue the condition compares against.
first_flaginputId of the first event flag the condition reads.
flaginputConfig/event flag id this line reads or writes.
flag_countinputHow many flag entries follow on this line.
gotoinputLabel to jump to when the condition holds (or always, for jump).
invertinputBit 7 of condition: when 1 the condition result is inverted.
isinputJump when the tested value equals this.
item_or_stateinputItem or object-state operand, depending on the selector on this line.
item_or_state_selectorinputSelects which item or state the handler acts on.
kindderivedReadable name for the variant this line selects, derived from its selector byte. It is cross-checked on compile, so it cannot disagree with the selector.
lookup_modederivedMode selector for lookup; the handler branches on it.
lookup_script_idinputIdentifier selecting which lookup script to use.
mask_modeinputMode selector for mask; the handler branches on it.
object_state_selectorinputSelects which object state the handler acts on.
property_offsetderivedOffset applied to property.
property_selectorinputSelects which property the handler acts on.
required_maskinputBitmask selecting which parts of required apply.
requires_allderivedWhether every all must match rather than any one of them.
script_lookup_controlinputBitmask controlling which optional script lookup values follow.
selectorinputSub-selector byte choosing which variant of the command's behaviour runs.
state_selectorinputSelects which state the handler acts on.
status_selectorinputSelects which status the handler acts on.
targetinputLabel this branch jumps to.
time_component_maskderivedBitmask selecting which parts of time component apply.
time_componentsderivedHuman-readable breakdown of the compared time value.
time_controlinputBitmask controlling which optional time values follow.
time_source_selectorderivedSelects which time source the handler acts on.
valueinputThe value the condition compares against.
yieldderivedPause the script here for one game frame; the next command runs on the following update. Lines without it keep running immediately.

Engine calls

Engine functions this handler was observed calling:

  • CRadiScript::CheckCondition(unsigned char,unsigned long,const SCR_DATA*)

Bit masks

Masks the handler applies to its argument byte or operand words:

0x00FF