Skip to content

Fix callback state reset before execution - #5

Open
FleepS wants to merge 1 commit into
boiidevelopment:mainfrom
FleepS:fix/callback-reentrancy
Open

Fix callback state reset before execution#5
FleepS wants to merge 1 commit into
boiidevelopment:mainfrom
FleepS:fix/callback-reentrancy

Conversation

@FleepS

@FleepS FleepS commented Jul 10, 2026

Copy link
Copy Markdown

Fix callback cleanup order in minigame result handler

Problem

When a new minigame was started from inside the callback of a previous minigame, the new callback reference was being cleared before it could be executed.

Example:

local minigame = {
	game = 'bit_flip',
	data = {
		length = 8, -- length of code sequence to solve
		timer = 8000 -- total time allowed
	}
}

exports.mgc:start_game(minigame, function(result)
	if result.success then
		exports.mgc:start_game(minigame, function(result2)
			if result2.success then
				print("MINIGAME SUCCESS")
			else
				print("MINIGAME FAILED")
			end
		end)
	else
		print("MINIGAME FAILED")
	end
end)

print("MINIGAME SUCCESS") was never reached.

Fix

Store the current callback reference locally and clear the internal callback state before executing the callback.
This ensures that callbacks can safely start new minigames without affecting the lifecycle of the new callback.

Result

Multiple minigames can now be chained correctly.
Callback state is cleaned up before external code is executed.
Nested minigame executions no longer overwrite or clear active callbacks.

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.

1 participant