Skip to content

feat(scripting): expose Genie 4 reserved variables to scripts (#45)#50

Merged
monil2233 merged 1 commit into
GenieClient:mainfrom
dylb0t:feature/reserved-script-vars
Jun 6, 2026
Merged

feat(scripting): expose Genie 4 reserved variables to scripts (#45)#50
monil2233 merged 1 commit into
GenieClient:mainfrom
dylb0t:feature/reserved-script-vars

Conversation

@dylb0t
Copy link
Copy Markdown
Collaborator

@dylb0t dylb0t commented Jun 5, 2026

Pull Request

Summary

Fills gaps in the reserved-variable vocabulary that scripts read as $name, so community scripts ported from Genie 4 resolve them instead of aborting on an undefined $var.

  • Computed clock vars in ScriptEngine.TryResolveVar: $date, $time, $time24, $datetime, $datetime24, $militarytime, $dayofmonth, $dayofyear, $unixtime. Formats copied verbatim from Genie 4 (Lists/Globals.cs), including the $time24 "tt" quirk, for parity. Resolved as a final fallback so a user var of the same name can shadow.
  • $scriptlist: '|'-separated running script names, or "none" (G4 parity), computed on read from the live instance list.
  • Session statics seeded in ScriptGlobalsSync: $account, $client ("Genie Client 5"), $version (host version string).
  • $lastcommand: set on every line sent to the game (ICommandHost.SendToGame).
    Describe what this pull request changes.

Type of Change

  • Bug fix
  • [ x ] New feature
  • Documentation update
  • Plugin update
  • Map update
  • Build/tooling change
  • Other

Related Issue

Doesn't close, but addresses some of #45

Testing

Verified via a throwaway harness driving the real ScriptEngine: all 11 variables round-trip through the substitution path (clock vars, scriptlist showing the running script, lastcommand, and the statics).

Checklist

  • [ x ] I kept this pull request focused and reasonably scoped
  • [ x ] I tested the change where practical
  • [ x ] I updated documentation if needed
  • [ x ] I understand this contribution will be distributed under the repository’s existing license

Follow-up

Follow-ups (dependency-heavy, left on the issue): $zoneid/$zonename and $roomnote (mapper state), $monstercount/$monsterlist (creature parsing), $gamehost/$gameport (resolved connection plumbing), spell-timer vars.

…lient#45)

Fills gaps in the reserved-variable vocabulary that scripts read as
$name, so community scripts ported from Genie 4 resolve them instead of
aborting on an undefined $var.

- Computed clock vars in ScriptEngine.TryResolveVar: $date, $time,
  $time24, $datetime, $datetime24, $militarytime, $dayofmonth,
  $dayofyear, $unixtime. Formats copied verbatim from Genie 4
  (Lists/Globals.cs), including the $time24 "tt" quirk, for parity.
  Resolved as a final fallback so a user var of the same name can shadow.
- $scriptlist: '|'-separated running script names, or "none" (G4 parity),
  computed on read from the live instance list.
- Session statics seeded in ScriptGlobalsSync: $account, $client
  ("Genie Client 5"), $version (host version string).
- $lastcommand: set on every line sent to the game (ICommandHost.SendToGame).

Verified via a throwaway harness driving the real ScriptEngine: all 11
variables round-trip through the substitution path (clock vars, scriptlist
showing the running script, lastcommand, and the statics).

Follow-ups (dependency-heavy, left on the issue): $zoneid/$zonename and
$roomnote (mapper state), $monstercount/$monsterlist (creature parsing),
$gamehost/$gameport (resolved connection plumbing), spell-timer vars.
@monil2233 monil2233 merged commit dab258a into GenieClient:main Jun 6, 2026
4 checks passed
monil2233 added a commit that referenced this pull request Jun 6, 2026
)

Follow-up to #50. $gametime is the server's clock (Unix seconds) carried
on each <prompt time='...'> tag — distinct from $unixtime (local wall
clock). The parser already captures it as PromptEvent.ServerTime; this
surfaces it to the script globals.

Routes PromptEvent through a new OnPrompt handler that sets $gametime from
ServerTime.ToUnixTimeSeconds(), guarded by > UnixEpoch so a prompt without
a time attribute never publishes a bogus negative epoch. Seeded to "0" in
SeedInitial for scripts that read it before the first prompt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants