Skip to main content

Scripted characters, flags and messages

Scripts · SCRIPT_DIALOGUE · ScriptFlagTarget

In brief​

Scripts damage, heal and reward characters, set and clear the flags that remember what has happened, allow or forbid resting, print messages, drive dialogue screens whose answers the next conditions test, play sounds, wait, launch objects and run special events and sequences.

How a script uses a dialogue question. The dialogue screen opens with a picture and a text. A question offers two or three answers labelled with strings of the level; the answer chosen, numbered from 1, becomes the run variable. A condition then tests the run variable: when it does not hold, the script jumps to another offset; when it holds, the next command runs. The game loop does not run meanwhile.
A dialogue answer steers the script through the run variable.

Characters​

Healing or hurting directly. SCRIPT_MODIFY_CHARACTER_HP adds a signed amount to the current hit points of one character or of all six that are present and not dead, without exceeding their maximum, and redraws their hit points and portraits. A negative amount has no lower limit and never kills. No original script uses it.1

Damaging characters. SCRIPT_DAMAGE_CHARACTERS affects one character or all six. For each, the game rolls the damage dice, may grant a saving throw that halves or cancels the damage ( ScriptSavingThrowType, ScriptSavingThrowEffect), applies the ScriptDamageFlags, and subtracts the result from an eligible character's hit points ( CharacterEligibilityMask). A character at −10 hit points or below dies. In the original scripts the flags either let a ring of Feather Fall cancel falling damage or change nothing.2

Awarding experience. SCRIPT_AWARD_EXPERIENCE with SCRIPT_EXPERIENCE_PARTY (ScriptExperienceTarget) divides an amount equally, rounding toward zero, between the characters that are present and not dead; if none is, nobody receives anything. Each share then follows the ordinary experience rules. A negative amount removes experience, and one that takes it below zero makes the class gain levels. No original script uses it.3

Flags and resting​

SCRIPT_SET_FLAGS and SCRIPT_CLEAR_FLAGS are how scripts remember what has happened. Their target is a ScriptFlagTarget:4

TargetSetClear
SCRIPT_FLAG_TARGET_LEVELOne bit of the current level's 32 flagsClears that bit
SCRIPT_FLAG_TARGET_GLOBALOne bit of the 32 global flagsClears that bit
SCRIPT_FLAG_TARGET_RUN_VARIABLERun variable = 1Run variable = 0
SCRIPT_FLAG_TARGET_REST_ALLOWEDThe party may restThe rest command refuses
SCRIPT_FLAG_TARGET_MONSTERProvokes a monsterNo effect; the instruction takes 3 bytes

Level flags typically record that a message has been shown or a puzzle solved; global flags carry such facts from one level to another. The rest setting survives level changes and is saved with the game; levels 2, 7 and 16 use it — on level 7, for example, resting is forbidden before a lightning trap. The other conditions of a rest are described under resting.

Messages, dialogue, sound and timing​

Messages. SCRIPT_PRINT_MESSAGE prints one of the level's strings in a chosen color. When the text names a character, it is the character selected by the last condition or, failing that, the first eligible character from a random starting slot. SCRIPT_DRAW_SCENE redraws the view, which scripts do after changing walls or moving the party.5

Dialogue screens. SCRIPT_DIALOGUE drives the illustrated dialogue screen through a sequence of ScriptDialogueCommand values: open the screen and load the dialogue texts of TEXT.DAT, draw a region of a named picture (ScriptDialogueBitmapFrame), show a text with an optional prompt, ask a question, and restore the normal view. A question offers two or three answers labelled with strings of the level; the answer chosen, numbered from 1, becomes the run variable that the next conditions test. Texts are word-wrapped in a ten-line window below the picture and shown a page at a time; the player answers a prompt with Space, Enter, M or a click on its button, and picks an answer with the mouse, or with the Left and Right arrows and Enter. The game loop does not run meanwhile, so monsters and timed events wait for the player (text window and pages, answer buttons).6

Sound and delays. SCRIPT_PLAY_SOUND plays a sound effect at once, or as an environmental sound coming from a block: louder the nearer the block, dropped beyond a distance of 15, and played at the end of the game loop's pass unless another environmental sound comes first. Sound numbers above 127 are read as negative and play nothing. SCRIPT_DELAY waits until the game's free-running counter has advanced by the given number of ticks, about 55 ms each; the game loop does not run meanwhile.7

Special events and sequences​

Launching objects. SCRIPT_LAUNCH_OBJECT sends a magic flying object (SCRIPT_LAUNCH_MAGIC, ScriptLaunchKind) or a copy of an item flying from a block in a direction, as a monster spell or a thrown item launched by no character. The original scripts launch fireballs as traps, and twice a dart.8

Special events. SCRIPT_SPECIAL_EVENT runs one of seven fixed routines (ScriptSpecialEvent): a lightning effect drawn before lightning damage, choosing a party member, a level gain for that member, the resurrection of a dead member or of a character whose bones the party carries, the recruitment of a particular character, the removal of two quest items, and the reloading of the level's wall graphics. Choosing a member and resurrection report their result in the run variable.8

Sequences. SCRIPT_RUN_SEQUENCE starts a larger scripted sequence selected by a ScriptSequenceSelector: conversations with non-player characters, which may end with one joining the party, a portal animation and a copy-protection check. Some conversation choices change global flags or the party's direction. The portal animation releases the level's door, monster and decoration shapes and does not change level itself: the script that follows does. The script resumes only if the sequence returns.9

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references. Statements about the original levels come from decoding the scripts of the 16 reference INF files listed in the file inventory.

Footnotes​

  1. Hit-point handler, the hit-point adjustment and the hit-point display. Comparative source: oeob_modifyCharacterHitPoints (REF-SCUMM-003). ↩

  2. Damage handler and character damage, including the saving throw. Comparative source: oeob_calcAndInflictCharacterDamage (REF-SCUMM-003). ↩

  3. Experience handler and experience sharing. Comparative source: oeob_increasePartyExperience (REF-SCUMM-003). ↩

  4. Set-flags and clear-flags handlers, the level flags, the rest flag and the rest routine. Comparative source: oeob_setFlags and oeob_removeFlags (REF-SCUMM-003). ↩

  5. Message handler, the string lookup, the redraw handler and the scene redraw. Comparative source: oeob_printMessage_v2, getString and oeob_drawScene (REF-SCUMM-003). ↩

  6. Dialogue handler and the dialogue routines of the text loader, text display and screen setup, with the wait prompt and the choice menu. Comparative source: oeob_dialogue (REF-SCUMM-012). ↩

  7. Sound and delay handlers, the sound effect player and the environmental sound. Comparative source: oeob_playSoundEffect and oeob_delay (REF-SCUMM-003). ↩

  8. Launch and special-event handlers, with create a magic flying object and launch an item. Comparative source: oeob_launchObject and oeob_specialEvent (REF-SCUMM-003). ↩ ↩2

  9. Sequence handler, the sequence dispatcher, the choice menu, the portal animation and the protection check. Details and comparative sources are on the sequence instruction page. ↩