Skip to content

0x14 — expr (assign and calculate)

Evaluates two typed integer operands from the command stream, combines them with an arithmetic/logical operation selected by low command bits, then optionally writes the result to config/event flags, script event values, character data, item data, or script-local float slots.

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

At a glance

Opcode0x14 (20)
HandlerCRadiScript::Command_14
SignatureCRadiScript::Command_14(int,SCR_DATA*,unsigned int,unsigned int)
Translation unitr_script_run0.cpp
Address— debug build; click for all 3
Handler size0x69C (1692 bytes)
Engine nameexpr
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
set_valueexprPuts a value into the target, replacing what was there (`target = value`).
add_valueexprAdds to the target (`target = target + value`).
sub_valueexprSubtracts from the target (`target = target - value`).
mul_valueexprMultiplies the target (`target = target * value`).
div_valueexprDivides the target (`target = target / value`).
mod_valueexprReplaces the target with the remainder after dividing (`target = target % value`). Scripts use it to wrap a counter.
keep_only_bitsexprThrows away everything the target has that the value does not, keeping only what both have (a bitwise AND). Scripts use it to isolate part of a value, or to cut one down to 16 bits with `value=65535`.
turn_on_bitsexprSwitches on whatever the value has, leaving everything else in the target alone (a bitwise OR). To switch a single character flag on or off, use `set_character_flag` / `clear_character_flag` instead.
set_character_flagexprSwitches one of a character's eight script flags on. The flags are storage for scripts: the game never reads them, it only clears them when the character's schedule list is released.
clear_character_flagexprSwitches one of a character's eight script flags off again. See `set_character_flag`.
eval_int_expression—Raw form of the value command. Prefer set_value, add_value and the other named operations, which say what they do to the target.

Handler behaviour

Evaluates two typed integer operands from the command stream, combines them with an arithmetic/logical operation selected by low command bits, then optionally writes the result to config/event flags, script event values, character data, item data, or script-local float slots.

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   |  0x14          |
+----------------+----------------+----------------+----------------+

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

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

FieldRoleMeaning
characterinputWhose property it is: current, party1..party5, or a character id.
controlderivedPacks op, target_from and value_from.
event_valueinputScript event value id this line writes (the friendly target form).
flaginputConfig/event flag id this line writes (the friendly target form).
flag_bitsinputNames of the bits set in the matching packed value.
lhs_typederivedWhich kind of lhs this is; the handler branches on it.
opderivedHow value combines with the target: 0 set, 1 add, 2 sub, 3 mul, 4 div, 5 mod, 6 and, 7 or. Usually implied by the head: set_value, add_value, sub_value, mul_value, div_value, mod_value, keep_only_bits, turn_on_bits.
propertyinputNamed character property this line writes: hp, hp_max, money, experience, volty, friend_list, equipped_skill, evasion, and the battle-only names; unknown codes stay as hex.
rhs_typederivedWhich kind of rhs this is; the handler branches on it.
stand_componentinputWhich component of a stand position the value comes from.
targetinputWhat gets written. Its top byte is the property code and the low 24 bits are the subject, such as the character id.
target_frominputWhich domain target addresses: 0 config/system event flag, 1 script event value, 2 character property, 5 item/other.
target_propertyderivedProperty code in the top byte of target, indexing the domain's parameter table. Known character codes: 0x00 HP, 0x01 HP Max, 0x03 evasion, 0x06 Money, 0x38 Equipped Skill, 0x3F Volty, 0x44 Experience, 0x48 Friend List. Battle-only codes (no effect outside battle): 0x0A guard counter, 0x0B damage counter, 0x0C status-ailment state, 0x32 battle target, 0x33 magic charge count, 0x36 magic level, 0x37 owner character, 0x39 using-item number, 0x3B fake death, 0x42 last stolen item, 0x46 active eternal tactics, 0x47 formation. Other reads: 0x21 schedule percent, 0x2B item count, 0x3D move progress percent.
valueinputThe operand combined with the target.
value_frominputWhere value comes from, using the same domain codes as target_from. 0xF means it is an immediate literal, which is 82% of all uses.
value_from_characterinputRead the value from a character property: whose character.
value_from_eventinputRead the value from this script event value instead of a literal.
value_from_flaginputRead the value from this config/event flag instead of a literal.
value_from_flag_bitsinputNames of the bits set in the matching packed value.
value_from_propertyinputRead the value from a character property: which property.
value_from_standinputRead the operand from a stand position instead of a literal.
value_from_systeminputRead the value from a system/config parameter word.
value_propertyderivedProperty code in the top byte of value, when value_from names a property domain.
wordsinputRaw fallback payload, used when a command shape has no named form yet.
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:

  • CRadiApp::GetConfigEventFlag(unsigned int) const
  • CRadiApp::SetConfigEventFlag(unsigned int,bool)
  • CRadiScript::GetAbstractionCharacterNumber(unsigned int&,unsigned int&,const SCR_DATA*)
  • CRadiScript::GetAbstractionItemNumber(unsigned int&,const SCR_DATA*)
  • CRadiScript::GetAbstractionStandPosNumber(unsigned int&,CVector&,CVector&,const SCR_DATA*)
  • CRadiScript::GetEventValueForScript(int,const SCR_DATA*)
  • CRadiScript::SetEventValueForScript(int,int,SCR_DATA*)
  • GetAbstractionCharacterNumber(unsigned int&)
  • __ptmf_scall

Bit masks

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

0xFFFF 0x00FF 0x000F 0x0007 0x0001