Skip to content

LUA error on first update tick — attempt to call nil value at RandomWorldEvents.lua:1044 #20

@TheCodingDad-TisonK

Description

@TheCodingDad-TisonK

Summary

On every session load, the mod throws a LUA error on its first `update` tick. The error fires once and does not repeat, but indicates a nil function reference that is only hit at runtime — likely a method that isn't available yet at the point in the update cycle where it's called.

Log Evidence

From `log.txt` (2026-05-22, 11:25:04 — approximately 3 minutes after map load):

2026-05-22 11:25:04.932 Error: Running LUA method 'update'.
C:/Users/.../mods/FS25_RandomWorldEvents/RandomWorldEvents.lua:1044: attempt to call a nil value

The error fires exactly once per session and does not recur. Despite this, the mod continues to run (NPC integrations, MarketDynamics integration, and CropStress integration all reference it successfully later in the log).

Timing Context

The error fires at 11:25:04, which is approximately when the player character finishes loading into the world (flashlight i3d loads at 11:25:04.944 immediately after). This suggests the update tick hits before some external dependency is fully initialised.

Likely Root Cause

Line 1044 calls a method (or indexes a table method) that is `nil` on the first update tick. This could be:

  • A method on `g_currentMission` or a sub-system that isn't ready yet
  • A callback registered by another mod that hasn't finished loading
  • An internal method that was renamed/removed and the call site wasn't updated
  • A conditional guard missing before the call (e.g., should check `if self.someSystem ~= nil then`)

Expected Behaviour

The first update tick should be guarded against nil references. A typical pattern:

-- RandomWorldEvents.lua around line 1044
if self.someSystem and self.someSystem.someMethod then
    self.someSystem:someMethod(...)
end

Or defer first-tick logic until after `onStartMission` / `loadMission00Finished` has confirmed all systems are ready.

Impact

  • One error line per session — low severity in isolation
  • If the nil call path is part of an important initialisation, some event state may not be set up correctly on first tick, potentially causing subtle bugs (e.g., a world event that should have triggered at session start being skipped)
  • The error makes it harder to trust the log is clean

Steps to Reproduce

  1. Load any savegame with FS25_RandomWorldEvents installed
  2. Wait for the player to fully load into the world
  3. Check log.txt — the error fires within the first few seconds of gameplay

Files Affected

  • `RandomWorldEvents.lua` — line 1044, the nil method call

Metadata

Metadata

Assignees

No one assigned

    Labels

    user-repliedUser is awaiting response

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions