Skip to content

Fix scenarios 23 and 24 failing at init - #2934

Open
dj803 wants to merge 4 commits into
daid:masterfrom
dj803:fix-scenarios-23-24-init
Open

dj803 wants to merge 4 commits into
daid:masterfrom
dj803:fix-scenarios-23-24-init

Conversation

@dj803

@dj803 dj803 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Scenarios 23 (Defenders or Pirates) and 24 (Iris Siege) cannot start on current master. This PR fixes the init crashes and the getDockedWith() return value that crashes 23 a few minutes in.

What was wrong

  • findClearSpot (23, 24). findClearSpot asserts type(item.obj)=="table". Space objects are now entities, so type() returns "userdata" and the assert fires inside constructEnvironment before anything is created: scenario_23_pirate.lua:2460 / scenario_24_iris.lua:1717 ("... but got a userdata instead"). Scenarios 27 and 34 already accept userdata (5ac3bc9); 23 and 24 kept the old form (6 asserts per file).
  • WarpJammer faction (24). WarpJammer() has no faction, so warp_jammer_info[block_warp_jammer:getFaction()] indexes nil at scenario_24_iris.lua:1364. Seen as soon as the first fix lets 24 get that far.
  • getDockedWith (23, 32, others). Entity:getDockedWith() returns false when not docked. Scripts test ~= nil and then index the result, so scenario_23_pirate.lua:3945 throws ("attempt to index a boolean value") a few minutes into a run; scenario_32_devour.lua:3906/4622 has the same pattern. The function now returns nil, as before the ECS rewrite.
  • finalStats (24). getPlayerShip(-1):getReputationPoints() is called when no valid player ship exists (defeat with no players). Falls back to 0.

Commits (separate so any can be dropped or changed)

  1. scenarios 23/24: findClearSpot accepts a userdata space object (12 one-line edits)
  2. scenario_24_iris: give the block warp jammer a faction
  3. Entity:getDockedWith() returns nil, not false, when not docked (scripts/api/entity/spaceship.lua, 1 line)
  4. scenario_24_iris: finalStats tolerates no valid player ship

getDockedWith is shared API

  • Audit of scripts/: 25 uses, none compares the result to true/false; all test == nil, ~= nil or truthiness. None in src/. Scenarios 22, 23, 24, 27, 32, 33, 34, 44, 48, 56, 57, 74 and comms_scenario_utility.lua call it.
  • Risk: a third-party script that compared to false would change behaviour.
  • Happy to turn this into a script-side if docked_with then fix at each site instead if you prefer to keep the API as it is. That is ~15 edits across ~10 scenarios.

Testing

  • scripts/ precheck (luaparse): 106 files, 0 failed.
  • Built master 73d057c + this branch (RelWithDebInfo, SeriousProton 81c347d). 60 s headless: before the PR, 23 and 24 stop at 23:2460 and 24:1717; after, both pass init.
  • Autopilot flights (our test harness, scenario scripts from this branch):
    • 23: 216 s, ran to an outcome, 0 pilot errors.
    • 32 (seed 2): 157 s, 357/358 ticks, 0 errors.
    • 24 with a spawned ship: runs 358 ticks and the changes in this PR no longer fail.
    • 24 with no ship: defeat fires as intended, no errors.
  • Not fixed here, still seen in those flights: 23:4379 (the Sweeper template has no create routine), and in 24 2587 (base_range nil in updatePlayerLongRangeSensors for a ship setPlayers has not set up yet) and 2478 (comms_data nil, goodsOnShip override takes 2 arguments). I have fixes for those and can send them as separate PRs.
  • Not tested: a crewed or GM session of 23 or 24 (the autopilot does not exercise comms menus, so the docked_with comms branches at 23:3988/32:4622 were only reached by reading), full playthroughs to a win, the other scenarios that call getDockedWith (33, 34, 44, 48, 56, 57, 74) at runtime, Linux/macOS.

🤖 Generated with Claude Code

dj803 and others added 4 commits November 15, 2026 10:11
Post-ECS space objects are userdata, not tables, so the type(item.obj)=="table"
assert in findClearSpot fired inside constructEnvironment at init and the scenario
never started (reproduced on unpatched master). Accept table or userdata.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
WarpJammer() has no faction, so warp_jammer_info[block_warp_jammer:getFaction()]
indexes nil in constructEnvironment and the scenario stops at init (seen once the
findClearSpot assert is fixed). Set it to Independent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pre-ECS API returned nil; scripts test 'docked_with ~= nil' (scenarios
22, 23, 24, 27, 32, 33, 34, 44, 48, 74) and then call docked_with:getCallSign()
or read .comms_data, which throws on a boolean false. Observed: scenario 23
comms at line 3945 (flight crashed at 706 s), 32:4622.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
finalStats reads getReputationPoints() from getPlayerShip(-1), which is nil or
invalid once every player ship is gone (the 'All players destroyed' defeat path,
and a game with no ship yet). Fall back to 0 instead of calling a nil method.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oznogon

oznogon commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

general note that crashes or failures specific to ECS/master-branch might be potential signs of reverse scenario API compatibility breakage, and if so might need to be addressed in the API instead of the scenarios

if these changes cause failures with the scenario in the as-tested-in 2024.12.08 release, they might not be desirable changes

@dj803

dj803 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that's a fair point. Both scenarios were written against 2024.12.08 (ee_version at 23:76 and 24:50), and 2024.12.08 is from before the ECS change, so I went through each commit against that tag:

  • findClearSpot: objects were Lua tables before ECS and are userdata now. The edited check accepts both, so it still works on 2024.12.08. I don't think this can be fixed in the API, since it's the Lua type itself. 27 and 34 were changed the same way in 5ac3bc9.
  • WarpJammer faction: you're right, this is an API change. Before ECS, every object started in faction 0, "Independent" (spaceObject.cpp:238 at the tag). WarpJammer() in scripts/api/entity/warpjammer.lua sets no faction, so getFaction() returns nil. Artifact, Asteroid, Nebula, Planet and Zone are the same. I could move this into the API: either a default faction in those constructors, or a fallback in Entity:getFaction(). Would either of those be preferred? I'd then drop the scenario edit.
  • getDockedWith: this one is already an API fix. Before ECS it returned nil (spaceship.h:340 at the tag).
  • finalStats: getPlayerShip(-1) returned nil with no player ship on 2024.12.08 too (gameGlobalInfo.cpp:432), so this fails there as well. The guard works on both versions.

The same question applies to some of my other open PRs. Most of the guards in #2908, #2909 and #2913, and part of #2914, work around two API changes:

  1. Calling a method on a destroyed object did nothing before ECS. Now luaEntityIndex returns nothing for it (SeriousProton environment.cpp:92), so the call raises "attempt to call a nil value". Returning a do-nothing function there for API methods would make most of those guards unnecessary. Field access on destroyed objects would still return nil.
  2. getPlayerShip(n) with no ship in that slot returned nil before ECS. Now it returns an invalid entity that isn't nil (script.cpp:601-614), so if p ~= nil then p:... fails. It could return nil again, but that might affect scripts written as getPlayerShip(-1):isValid().

Would API-side fixes for these be wanted? If so, I'll send those and cut the scenario guards down to the real scenario bugs.

I checked all of this by reading the code at the tag. I haven't run the changed scenarios on a 2024.12.08 build.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
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