Skip to content

Conversation

@unboundlopez
Copy link
Owner

Motivation

  • Prevent hard crashes when modtools/create-unit is invoked on Steam DFHack builds that expose arena state under a different field layout.
  • Make arena-related setup/restore resilient to missing optional fields so spawning can proceed or fail with a clear diagnostic instead of a nil-index error.
  • Provide a small, prompt-driven spawn-unit wrapper that preserves interactive flow while delegating actual unit creation to the Steam-aware modtools/create-unit implementation.

Description

  • Update modtools/create-unit.lua to prefer df.global.world.arena_spawn and fall back to df.global.world.arena, and qerror if no arena spawn state is available.
  • Guard optional arena fields (type, filter, interaction, tame) with nil checks and only restore them if previously saved, preventing nil-index crashes on Steam layouts.
  • Make arena-open and selection input resilient by attempting ARENA_CREATE_CREATURE first then D_LOOK_ARENA_CREATURE, and use a table-form SELECT fallback when direct SELECT delivery fails.
  • Add a new spawn-unit.lua script that provides an interactive list/input prompt flow, validates fortress mode and cursor position, validates race/caste and count, and delegates spawning to create_unit.createUnit(...) inside a pcall, exposing do_spawn when loaded as a module (dfhack_flags.module).

Testing

  • Static pattern checks using rg confirmed the arena_spawn fallback and the key/input fallbacks are present in modtools/create-unit.lua (succeeded).
  • File inspection with nl/sed verified the guarded field handling and the new spawn-flow code paths are present (succeeded).
  • No end-to-end Steam DF/DFHack runtime was available in this environment, so no live spawn integration could be executed (not executed).

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 745262ed38

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +314 to +315
if not spawnOpen then
break

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fail loudly when arena menu cannot be opened

In createUnitInner, if neither arena-open key can be injected, the code just breaks out of the spawn loop and returns whatever was created so far (often zero) without an error. That turns an environment/keybinding incompatibility into a silent under-spawn, which is especially misleading for callers like spawn-unit that treat a returned table as success. This path should raise a diagnostic instead of silently exiting.

Useful? React with 👍 / 👎.

Comment on lines +319 to +320
if not selected then
pcall(function() gui.simulateInput(spawnScreen, {SELECT=true}) end)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop processing when creature SELECT input fails

If SELECT fails, the fallback pcall result is ignored and execution continues as if a creature was spawned. In that failure case, the subsequent df.unit.find(df.global.unit_next_id-1) can point to a pre-existing unit, so processNewUnit(...) may mutate the wrong creature (nickname/domestication/flags), corrupting game state. The spawn path should verify that selection succeeded (or that a new unit id was allocated) before continuing.

Useful? React with 👍 / 👎.

@unboundlopez unboundlopez deleted the codex/create-dfhack-script-to-spawn-units branch February 8, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant