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
| Opcode | 0x14 (20) |
|---|---|
| Handler | CRadiScript::Command_14 |
| Signature | CRadiScript::Command_14(int,SCR_DATA*,unsigned int,unsigned int) |
| Translation unit | r_script_run0.cpp |
| Address | — debug build; click for all 3 |
| Handler size | 0x69C (1692 bytes) |
| Engine name | expr |
| Family | Script control, flags and values |
| Command size | 4 + 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.
| Form | Engine name | What it does |
|---|---|---|
set_value | expr | Puts a value into the target, replacing what was there (`target = value`). |
add_value | expr | Adds to the target (`target = target + value`). |
sub_value | expr | Subtracts from the target (`target = target - value`). |
mul_value | expr | Multiplies the target (`target = target * value`). |
div_value | expr | Divides the target (`target = target / value`). |
mod_value | expr | Replaces the target with the remainder after dividing (`target = target % value`). Scripts use it to wrap a counter. |
keep_only_bits | expr | Throws 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_bits | expr | Switches 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_flag | expr | Switches 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_flag | expr | Switches 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.
| Field | Role | Meaning |
|---|---|---|
character | input | Whose property it is: current, party1..party5, or a character id. |
control | derived | Packs op, target_from and value_from. |
event_value | input | Script event value id this line writes (the friendly target form). |
flag | input | Config/event flag id this line writes (the friendly target form). |
flag_bits | input | Names of the bits set in the matching packed value. |
lhs_type | derived | Which kind of lhs this is; the handler branches on it. |
op | derived | How 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. |
property | input | Named 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_type | derived | Which kind of rhs this is; the handler branches on it. |
stand_component | input | Which component of a stand position the value comes from. |
target | input | What gets written. Its top byte is the property code and the low 24 bits are the subject, such as the character id. |
target_from | input | Which domain target addresses: 0 config/system event flag, 1 script event value, 2 character property, 5 item/other. |
target_property | derived | Property 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. |
value | input | The operand combined with the target. |
value_from | input | Where 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_character | input | Read the value from a character property: whose character. |
value_from_event | input | Read the value from this script event value instead of a literal. |
value_from_flag | input | Read the value from this config/event flag instead of a literal. |
value_from_flag_bits | input | Names of the bits set in the matching packed value. |
value_from_property | input | Read the value from a character property: which property. |
value_from_stand | input | Read the operand from a stand position instead of a literal. |
value_from_system | input | Read the value from a system/config parameter word. |
value_property | derived | Property code in the top byte of value, when value_from names a property domain. |
words | input | Raw fallback payload, used when a command shape has no named form yet. |
yield | derived | Pause 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) constCRadiApp::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