Skip to content

rq ​

since 0.2.0

The global table every mod uses to reach the game.

The engine builds rq before any mod runs. Mods load before the game starts, so at the top level of init.lua register callbacks and definitions (rq.on_frame, on_*, define, edit, patch, rq.image.add). Calls that read or change game state, such as rq.skill.get, rq.chara.get, rq.item.give, rq.party.* or rq.hud.text_width, raise an error there: make them from rq.on_frame or a callback. The queries rq.units(), rq.items(), rq.quests() and rq.castle() return empty results at that point.

Every on_* call, rq.on_frame and rq.ain.hook return a function that removes the callback. It works at once, also from inside the callback, and calling it twice is harmless. Definitions (define, edit) are not callbacks and have no remover.

lua
local remove
remove = rq.battle.on_end(function(ev)
  rq.log("the first fight ended")
  remove()
end)

Namespaces ​

NamespaceSummary
rqThe global table every mod uses to reach the game.
rq.agentLets the test pipe (rqmod-ctl) see and press a mod's controls.
rq.ainReaches into the game's own code (the AIN): call, hook and patch its functions, and read and write its globals.
rq.battleHooks into fights: events, ally skill select, marks and buffs on the cards, faces, states, drops, and scripted fights.
rq.castleReads the castle: whether it is open, its rooms and who is in them.
rq.charaReads and changes characters: their skills, stats, the skill buy list, and the roster.
rq.chestThe chance of opening a red chest.
rq.combatChanges physical damage, accuracy and criticals.
rq.configA Mods tab in the game's Config screen.
rq.counterLets the Counter skill (259) work after Ally Guard.
rq.debugAdds rows to the engine's F3 debug menu.
rq.dungeonReads and changes the dungeon: the map, the player's place, objects on it, and the camera.
rq.encountersRandom fights on a quest's map.
rq.gameThe player's money and charisma, as the system bar shows them.
rq.gamebuttonButtons of mods in the game's own menus, made by the game itself.
rq.hudDraws text, boxes and CGs over the game, and reads clicks on them.
rq.idsThe game's numbers by name: characters, items, monsters, quests, skills, and the small lists the game names (classes, states, races, character types, elements, item kinds, skill targets).
rq.imageImages from a mod's folder, shown by the game as CGs.
rq.inputReads the mouse and keyboard, and drives them for the game.
rq.itemDefines, gives and changes items.
rq.itemsLists the item instances the player owns.
rq.knownskillsMore known skills than the game's 17, shown 17 at a time on the status page and in the skill window.
rq.lootChest loot: what the pools roll, and the items the player will find, known in advance.
rq.modFinds out about other mods, and reaches what they share.
rq.monsterThe game's list of monsters: read a monster's data, change it each time the game builds it, and change each enemy a fight builds. A mod's own monsters, enemy groups and models.
rq.musicMusic from a mod's own file, in place of one of the game's tracks.
rq.orbThe blue Recovery Spring on the map (回復の泉, object 203).
rq.partyReads and changes who is in the party.
rq.questsLists the quests and follows them: clears, endings, quest moments and state.
rq.randomControls the random number generator the game and the loader share.
rq.savedataEach mod's data that follows the game's save.
rq.savesSave profiles: whole save folders the player can switch between.
rq.scenePlays scenes with the game's own commands, so a mod can do anything a game scene does.
rq.shopAdds stock to Frostbuy, the item shop, and reports purchases.
rq.skillReads, defines and patches skills, and rewrites their hover text.
rq.skilllistPages the Potential Skills grid, 36 skills a page.
rq.soundPlays sounds: a game sound number, a file in the mod folder, or a sound inside a game Flash file.
rq.speedRuns the game clock faster or slower than real time.
rq.spriteSprites a mod makes once and changes later, drawn among the game's own in z order.
rq.statusBattle states made by mods, such as a burn, a bleed, a regeneration, a freeze or a weaken, that live beside the game's poison, stun and ▲▼, in one registry every mod shares.
rq.statuspageA character's status page, for mods.
rq.storeSmall key and value storage for each mod and each save profile.
rq.uiReads what is on the screen and saves screenshots.
rq.uikitWidgets in the look of the game's Config screen and, since 2.6.0, of its hub.
rq.unitsLists the recruited characters.
rq.worldThe world and the game's world transfer.

Properties ​

NameTypeDescription
versionstringThe loader version, such as "1.16.0". A mod whose mod.json asks for a newer loader is not loaded.
game_dirstringThe game folder (where the AIN is), in UTF-8 as every path the loader gives.
mods_dirstringThe mods folder, in UTF-8, with no backslash at the end.

Functions ​

NameSummary
rq.logWrites a line to the console and to the log.
rq.time_msReturns the time since the game started, in real milliseconds.
rq.tracebackReturns a stack trace, of the current code or of a coroutine.
rq.afterCalls fn once, ms milliseconds of real time from now.
rq.everyCalls fn every ms milliseconds of real time, until it returns false or is removed.
rq.spawnRuns fn as a job that can wait, with rq.wait and rq.wait_until.
rq.waitWaits ms milliseconds of real time, inside a job from rq.spawn.
rq.wait_untilWaits until cond returns a true value, inside a job from rq.spawn.

rq.log ​

lua
rq.log(...)

since 0.2.0 changed 1.1.0 changed 2.24.1

Writes a line to the console and to the log.

The line goes to logs\rqmod.log (the logs folder beside mods) and, when config.json has "terminal": true, to the console window. It starts with the id of the mod that called it (the id in its mod.json, as rq.mod.id gives it), such as [loot-preview] Detected 2 items, or [lua] outside a mod. Arguments are turned into text as tostring does and joined with tabs, as print does.

when a player renames the folder.

ParameterTypeDescription
...anyThe values to write.

Changed in 1.1.0: The log moved from mods to the logs folder.

Changed in 2.24.1: The tag is the mod's id; it was the name of the mod's folder, which differs only

rq.time_ms ​

lua
rq.time_ms() -> integer

since 0.20.0

Returns the time since the game started, in real milliseconds.

It keeps counting at real speed whatever rq.speed is set to. For something that runs later or every so often, rq.after and rq.every count on it.

ReturnsTypeDescription
msintegerMilliseconds since the game started.

See also: rq.after

rq.traceback ​

lua
rq.traceback(co, msg) -> string

since 0.20.0

Returns a stack trace, of the current code or of a coroutine.

The sandbox has no debug library; this gives what debug.traceback would.

ParameterTypeDescription
co (optional)thread|stringThe coroutine to trace, or the message when no coroutine is given.
msg (optional)stringA message put before the trace.
ReturnsTypeDescription
tracestringThe stack trace.

rq.after ​

lua
rq.after(ms, fn) -> fun()

since 2.33.0

Calls fn once, ms milliseconds of real time from now.

It runs from the loader's own rq.on_frame, at the first update after the time has passed, so it may run a little late but never early. The time is real: rq.speed does not change it, and it goes on after a load or the title (rq.on_reset can remove it). An error in fn is logged once for each new error text.

lua
rq.after(3000, function() rq.log("three seconds later") end)
ParameterTypeDescription
msnumberMilliseconds, 0 or more; 0 runs it at the next update.
fnfun()Runs once.
ReturnsTypeDescription
removefun()Cancels it, if it has not run yet.

See also: rq.every

rq.every ​

lua
rq.every(ms, fn) -> fun()

since 2.33.0

Calls fn every ms milliseconds of real time, until it returns false or is removed.

The first call comes ms from now. When updates are slower than ms, it runs once per update and does not catch up on the calls it missed. The time is real, as in rq.after. An error in fn is logged once for each new error text, and the timer goes on.

lua
local n = 0
rq.every(1000, function()
  n = n + 1
  rq.log("tick " .. n)
  if n == 5 then return false end  -- stops after five
end)
ParameterTypeDescription
msnumberMilliseconds, above 0.
fnfun(): boolean|nilReturns false to stop.
ReturnsTypeDescription
removefun()Stops it.

See also: rq.after

rq.spawn ​

lua
rq.spawn(fn, ...) -> rq.SpawnHandle

since 2.33.0

Runs fn as a job that can wait, with rq.wait and rq.wait_until.

The job starts at once and runs until its first wait; the loader then goes on with it on later updates, from its own rq.on_frame. A job may also call the game's waiting calls, such as rq.ui.confirm or rq.battle.start. An error ends the job and is logged with its stack trace.

lua
rq.spawn(function()
  rq.log("get ready")
  rq.wait(2000)
  local found = rq.wait_until(function() return rq.encounters.info() ~= nil end, 60000)
  if found then rq.log("on a map") end
end)
ParameterTypeDescription
fnfun(...): ...The job.
...anyArguments for fn.
ReturnsTypeDescription
jobrq.SpawnHandleThe job, to follow or cancel.

rq.wait ​

lua
rq.wait(ms)

since 2.33.0

Waits ms milliseconds of real time, inside a job from rq.spawn.

It waits at least one update, also for 0. The game goes on meanwhile, and so does the mod's other code.

Raises an error outside a job from rq.spawn: at the top level of a mod, in rq.on_frame, in a callback, or in a coroutine the mod made itself.

ParameterTypeDescription
msnumberMilliseconds, 0 or more.

See also: rq.spawn

rq.wait_until ​

lua
rq.wait_until(cond, limit) -> any

since 2.33.0

Waits until cond returns a true value, inside a job from rq.spawn.

cond is called at once, then once per update. With limit, it gives up after that many milliseconds of real time.

Raises an error outside a job from rq.spawn: at the top level of a mod, in rq.on_frame, in a callback, or in a coroutine the mod made itself.

lua
local s = rq.wait_until(function()
  local s = rq.ui.get()
  return s and s.screen == "hub" and s
end)
ParameterTypeDescription
condfun(): anyChecked once per update.
limit (optional)numberMilliseconds to wait at most. Default: no limit.
ReturnsTypeDescription
valueanyWhat cond returned, or nil when the limit came first.

See also: rq.spawn

Events ​

NameSummary
rq.on_frameCalls fn once on every game update.
rq.on_resetCalls fn after a load or after going to the title, once the game runs again.

rq.on_frame ​

lua
rq.on_frame(fn) -> fun()

since 0.2.0 changed 0.3.0

Calls fn once on every game update.

Draw with rq.hud.* here, and check input or game state. Every mod may register callbacks; they run in load order. An update is not a drawn frame: on a screen that does not redraw it can run thousands of times per second, so use rq.time_ms for anything that must last a real time. An error in fn is logged once for each new error text, not on every update.

lua
rq.on_frame(function()
  rq.hud.text(10, 10, "Hello from my mod")
end)
ParameterTypeDescription
fnfun()Runs on every update.
ReturnsTypeDescription
removefun()Removes this callback.

Changed in 0.3.0: Every mod keeps its own callback (before, the last mod replaced the others).

rq.on_reset ​

lua
rq.on_reset(fn) -> fun()

since 1.13.0

Calls fn after a load or after going to the title, once the game runs again.

Use it to clear a mod's own flags, such as "a scene is playing". For a load it runs when the game starts reading the save, before that save's rq.savedata is in: read that in rq.saves.on_load. These are the same callbacks as rq.sprite.on_reset, and they run after every mod sprite is gone. On the title, every Lua call that was waiting in the game (a scene, a fight from rq.battle.start) has already ended with the error "rq: the game went to the title".

ParameterTypeDescription
fnfun(why: "load"|"title")why says which one happened.
ReturnsTypeDescription
removefun()Removes this callback.

See also: rq.saves.on_load