Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 13, 2025

On every third light toggle, offExtras would turn ON instead of OFF when Default Stages feature was enabled.

Root Cause

In ULC:SetStage, the newState determination logic left newState as nil when an extra was already in its desired state:

-- Before: newState remains nil in these cases
if IsVehicleExtraTurnedOn(MyVehicle, extra) then
    if action == 1 or action == 2 then
        newState = 1
    end
    -- Missing: action == 0 leaves newState = nil
else
    if action == 0 or action == 2 then
        newState = 0
    end
    -- Missing: action == 1 leaves newState = nil
end

When setDefaultStages() calls with forceChange = true, processing continues despite nil newState, passing it to SetVehicleExtra() which interprets it incorrectly.

Changes

/ulc/client/c_buttons.lua - Added explicit newState assignments for both edge cases:

  • When extra is ON and action is 0 (enable): set newState = 0
  • When extra is OFF and action is 1 (disable): set newState = 1

This ensures newState is always defined when forceChange bypasses the early return check.

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: Unidentified bug with Default Stages</issue_title>
<issue_description>https://discord.com/channels/603591936372244501/1382451717743841421/1383197121498583040</issue_description>

<agent_instructions>make sure to review /docs for architecture info then attempt to identify and propose a fix for this bug.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@Flohhhhh It seems what's happening is every 1 in 3 Q presses (first being turn lights on, second turn lights off, third back on again) is instead of turning OFF "offExtras" it turns them ON instead.

It must be a bug related to the default stages feature since this only happens when light state toggles which is when default stages triggers.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ange

Co-authored-by: Flohhhhh <48927090+Flohhhhh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug with default stages affecting light toggling Fix Default Stages: prevent nil newState causing offExtras to toggle incorrectly Dec 13, 2025
Copilot AI requested a review from Flohhhhh December 13, 2025 16:50
Copilot AI requested a review from Flohhhhh December 13, 2025 17:08
@Flohhhhh Flohhhhh marked this pull request as ready for review December 13, 2025 17:18
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.

Bug: Unidentified bug with Default Stages

2 participants