New scripts, scenes and assets
Patches change what is there (patching.md). This page is about adding things: scripts of your own, a boot-time data edit, a scene the player can save in, and new assets. Your game guide (games/README.md) has the game’s values: how many catalogs it ships, what its scene registry holds, its saved range, and working examples.
Append catalogs
Section titled “Append catalogs”AGE games ship add-on content as append catalogs: APPENDnn.AAI (an index) and APPENDnn.ALF (the data). A mod
with new scripts or new assets gets a catalog of its own, built when the mods link:
- Records. The catalog’s records are your
[scripts].names, in order, then your[assets].names(packages.md). Each script isscripts/NAME.oms, a unit that beginsscript "NAME". - Selector. Each catalog has a number, its selector. The port allocates the lowest one that neither the
install’s own catalogs nor another mod use, and keeps it in
mods/selectors.tomlfor as long as the mod is installed, whatever the load order. Never rely on a particular selector. - Packed ids. The engine addresses record
nof catalogsas(s << 24) | n. Writerun NAMEandasset "NAME"and the linker fills these in, so a mod never hard-codes its own ids.
Data edits at boot
Section titled “Data edits at boot”Record 0, the first name in [scripts].names, runs once at boot, after the game’s own init scripts fill its data
tables. Keep it short and end it with exit (packages.md, “Record 0 runs at boot”). A record-0 script
can overwrite table entries:
oms 1script "AUTO"use <game>.globals
with unit[761] { .stats.max_hp = 150 .experience_reward = 999 } exitThe tables and their fields are listed in the game’s global reference, linked from its identity block.
Does the edit survive loading a save? Saves keep only a prefix of each global bank. Boot runs on every start, so a table cell above the saved range is rebuilt with your edit each time, and the edit holds after a load. A cell inside the saved range is overwritten by the loaded save. Your game guide gives the range; check your cells against it.
Calling your scripts
Section titled “Calling your scripts”From a patch or another of your scripts, run NAME calls a script and returns when it ends. A script with no ADV
page (a computation or a data edit) can always be called this way.
A script you run from a scene cannot be a scene itself. The scene that calls it owns the ADV menu and the
click handlers. If the player right-clicks during a text wait inside the called script, the engine sees a callback
that belongs to the caller while the callee runs. It stops with the error “Depth が不正です” (the engine’s “invalid
depth” error). Native AGE and the port both do this. Short pages inserted with a patch are fine, because they run in
the scene’s own frame. A run of pages in a separate script needs its own scene.
A scene of your own
Section titled “A scene of your own”To add a scene the player can open the menu, save and load in, make it a full scene that the scene scheduler enters, as it enters the shipped ones:
-
Copy a shipped scene’s skeleton. Decompile a shipped append scene with
--level idiomaticand keep everything except its content. That means the ADV handlers, hotspots, save-resume mark, load-restore code, and the per-pass setup and teardown. Then put your pages in the content subroutine. -
Register it. Your record-0 script makes the game’s scene dispatch reach your scene. Games differ here, and your game guide gives the form. Where the dispatch reads a registry that maps a story decision to a scene, write your scene’s id into a row:
scjump_scene_script_resource_ids[<decision>] = asset "SCENE"Where the dispatch runs a chain of rule scripts instead, give your scene a record and add a rule script of your own to the chain.
-
Let the story go on when it ends. With a registry row, clear the row at the end of the content and request the next scene:
scjump_scene_script_resource_ids[<decision>] = 0x0system_flow_request = 0x1scjump_decision_out = 0x0With a rule, mark the scene played at its start, and make the rule test that mark.
Which row or rule to use depends on what the game already has there. An empty registry row that falls back to another scene lets yours play first, while a row that holds a scene is replaced; a rule runs after the game’s own. Your game guide says how the recipe was tested in that game, and names the example scene to copy.
New assets
Section titled “New assets”A file in assets/ whose name the game does not have is a new asset. List it in [assets].names, and it becomes a
record of your catalog after the scripts. Use it wherever an instruction takes a resource id:
adv_gfx_resource_id = asset "MYBG.AGF"A file named like an original asset overrides that asset instead, and needs no listing (packages.md).
Using another mod’s scripts
Section titled “Using another mod’s scripts”Declare the other mod in [[requires]], then name its scripts and assets with its id:
run "example.library:HELPER"G[0x1234] = asset "example.library:ICON.AGF"Only mods you require are visible, and a required mod always loads before yours.
Keep records stable
Section titled “Keep records stable”Saves store scripts by packed id, which is selector plus record number. Once players have saves made inside your scripts:
- do not reorder or remove
[scripts].namesentries; add new ones at the end; - do not change the mod’s
id, because that makes it a different mod with a different selector.