empty debug screen at start/end of level

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

Gaming-Dojo
Tweeter
Tweeter
Posts: 144
Joined: Mon Jan 25, 2016 9:20 am
Pronouns: he/him
Contact:

empty debug screen at start/end of level

Postby Gaming-Dojo » Sun Aug 31, 2025 9:52 am

Hello folks.

While continuing work on my character select script, I encounter the weird issue of getting an empty debug screen at the end of the level and sometimes at the start, too. Do you have an idea what can cause this? This is pretty annoying, as it seems to reset a SaveData variable back to nil causing a onStart function to reset it to a default value instead of keeping the value it had before the level was ended.

Here's the screen I get:

Image

and here is the corresponding code:
Spoiler: show

Code: Select all

local characterselect = {}

local map_menu_open = false
local last_pressed = "none"

local style = "SMB3"

local chars = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/chars.png"))
local bg = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/bg_smb2.png"))
local lives_font = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/livesFont_smb2.png"))
local lives_number = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/numbers_smb2.png"))
local cursor = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/cursor_smb2.png"))
local charnames = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/charnames.png"))

local showNames = false -- whether or not the characterNames should be shown
local showLives = true -- whether or not lives count should be shown in the character select screen (like in SMB2
local drawCoords = {240,280} -- changes the position, where the first character is drawn. first entry is x coordinate, second is y coordinate.
local spacing = {86,140} -- determines, how far the cell for one character is apart from the cell for the next one. first entry is x spacing, second is y spacing.
local cols = 6 -- determines, after how many characters the next character should be drawn in a new row
local lives_position = {140,540} -- determines, where the lives will be drawn. First entry is x coordinate, second is y coordinate)
local cursor_offset = {20,-20} -- how much the cursor is offset from the top left corner of the character cell. First entry is x offset, second y offset
local number_offset = {400,0} -- how much the lives numbers are apart from the "lives", "extra lives" or similar text. First entry is x offset, second is y offset.
local number_spacing = 36 -- how much the single digits of the lives counter are apart (only x spacing)
local lettersize = {10,10}
local name_offsets = {-12,84}

function characterselect.onInitAPI()
	registerEvent(characterselect, "onStart", "onStart", false)
	registerEvent(characterselect, "onDraw", "onDraw", false)
	registerEvent(characterselect, "onInputUpdate", "onInputUpdate", false)
	registerEvent(characterselect, "onNPCCollect", "onNPCCollect", false)
	registerEvent(characterselect, "onTick", "onTick", false)
end

function characterselect.onStart() -- initializes some SaveData values and assures that certain SaveData is only set when a new SaveFile is created (e.g. chars_unlocked)
	
	if style == "SMB2" then
		
		bg = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/bg_smb2.png"))
		lives_font = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/lives_font_smb2.png"))
		lives_number = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/numbers_smb2.png"))
		cursor = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/cursor_smb2.png"))
		charnames = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/charnames_smb2.png"))
		
		drawCoords = {240,280}
		spacing = {86,140}
		cols = 6
		lives_position = {140,540}
		cursor_offset = {16,-28}
		lettersize = {9,9}
		number_offset = {400,0}
		name_offsets = {-12,84}
		showLives = true
		showNames = true
	end
	
	if style == "ALTTP" then
		
		bg = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/bg_alttp.png"))
		cursor = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/cursor_alttp.png"))
		
		drawCoords = {230,220}
		spacing = {100,110}
		cols = 6
		cursor_offset = {-36,30}
		showLives = false
		showNames = false
	end
	
		if style == "SMB3" then
		
		bg = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/bg_smb3.png"))
		cursor = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/cursor_smb3.png"))
		chars = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/chars_smb3.png"))
		
		drawCoords = {200,140}
		spacing = {100,140}
		cols = 6
		cursor_offset = {-4,-4}
		showLives = false
		showNames = false
	end
	
		if style == "MM" then
		
		bg = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/bg_megaman.png"))
		cursor = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/cursor_megaman.png"))
		charnames = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/charnames_megaman.png"))
		
		drawCoords = {310,94}
		spacing = {100,116}
		cols = 4
		cursor_offset = {60,40}
		lettersize = {10,10}
		name_offsets = {-8,92}
		showLives = false
		showNames = true
	end
	
	if style == "SMW" then
		
		bg = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/bg.png"))
		lives_font = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/lives_font.png"))
		lives_number = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/numbers.png"))
		cursor = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/cursor.png"))
		charnames = Graphics.loadImage(Misc.resolveGraphicsFile("charecterSelectGraphics/charnames.png"))
		
		drawCoords = {180,160}
		spacing = {90,122}
		cols = 8
		lives_position = {320,5}
		cursor_offset = {20,-20}
		lettersize = {10,10}
		number_offset = {280,0}
		showLives = false
		showNames = false
	end
	
	if SaveData.max_visible == nil then
		SaveData.max_visible = 1
	end
	
	SaveData.char_sel_open = false


	if SaveData.sel_char == nil then -- which character the player currently has selected to play as. If morio is not used, change the value from 1 to the first character you want to be visible on the character select screen.
		SaveData.sel_char = 1
	end
	
	if SaveData.char_hover == nil then -- determines, over which character the player currently moves the cursor. If morio is not used, change the value from 1 to the first character you want to be visible on the character select screen.
		SaveData.char_hover = 1
	end
	
	if SaveData.visible_id == nil then -- handles which characters should be visible in the character select screen to draw the correct characters at the correct positions
		SaveData.visible_id = 1
	end
	
	if SaveData.visible_chars == nil then -- handles which characters should be visible in the character select screen to draw the correct characters at the correct positions
		SaveData.visible_chars = {}
	end
end

function characterselect.onTick()

	if SaveData.coins == nil then
		SaveData.coins = 0
	end
	
	if SaveData.coins >= 10 and SaveData.chars_unlocked[7] ~= true then
		SaveData.chars_unlocked[7] = true
		Text.showMessageBox("You collected 10 coins. You can now play as Wario!")
	end
	
	if SaveData.coins >= 20 and SaveData.chars_unlocked[5] ~= true then
		SaveData.chars_unlocked[5] = true
		Text.showMessageBox("You collected 20 coins. You can now play as Link!")
	end
end
	
function characterselect.onNPCCollect(token,collectedNPC,collector)
	if collectedNPC.id == 10 then
		SaveData.coins = SaveData.coins + 1
	end
end

function characterselect.onInputUpdate()
	
	if SaveData.chars_unlocked == nil then
		SaveData.chars_unlocked = {true,true,true,true,false,"inv",false,true,"inv","inv",true,"inv",true,"inv","inv","inv"} -- Sets, whether a character should be unlocked (true), locked (false) or not visible at all ("inv") at the start of a new ganme. Later on in the game, states can be changed in the conditions.lua file. (useful for unlocking/taking away characters)
	end
	
	if player.keys.jump == KEYS_PRESSED then
		if SaveData.chars_unlocked[SaveData.char_hover] == true then
			SaveData.sel_char = SaveData.char_hover
		end
	end
	
	for k,v in ipairs(SaveData.chars_unlocked) do -- iterates over all characters via the chars_unlocked array, filters out the invisible characters and stores the rest in a separate array.	

		if v ~= "inv" then
			SaveData.visible_chars[SaveData.visible_id] = k
			SaveData.visible_id = SaveData.visible_id + 1
		end
		
	end
	
	if SaveData.visible_chars == nil then -- avoiding that the visible_chars array is nil
		SaveData.visible_chars = {}
	end
	
	if SaveData.char_hover < 1 then -- assures, that when the last character is hovered over, selection wraps to the first when pressing right
		SaveData.char_hover = 16
	end
	
	if SaveData.char_hover > 16 then -- assures, that when the first character is hovered over, selection wraps to the last when pressing left
		SaveData.char_hover = 1
	end
	
	if SaveData.chars_unlocked[SaveData.char_hover] ~= true then -- in-/ decreases the character by 1 if the char hovered over is not unlocked depending on whether right or left was pressed to reach the locked character
		if last_pressed == "left" then
			SaveData.char_hover = SaveData.char_hover - 1
		end
		
		if last_pressed == "right" then
			SaveData.char_hover = SaveData.char_hover + 1
		end
	end
	
	player.character = SaveData.sel_char -- sets the player character to the selected character all the time.
	
	if player.keys.pause == KEYS_PRESSED then
		
		if SaveData.char_sel_open == true then -- closes the character select menu, when the pause key is pressed
			SaveData.char_sel_open = false
		end
	end
		
	if SaveData.char_sel_open == true then -- in-/decreases the char hovered over by 1 when right/left is pressed. Sets last pressed key so it wraps correctly when reaching the start/end
			
		if player.keys.left == KEYS_PRESSED then
			last_pressed = "left"
			SaveData.char_hover = SaveData.char_hover - 1
		end
			
		if player.keys.right == KEYS_PRESSED then
			last_pressed = "right"
			SaveData.char_hover = SaveData.char_hover + 1
		end		
	end
end

function characterselect.onDraw() -- draws the menu, characters and cursor
	
	for k,v in ipairs(SaveData.chars_unlocked) do
		Text.printWP(k,5,k*15,15)
		Text.printWP(v,45,k*15,15)
	end
	
	if SaveData.char_sel_open == true then
	
		Graphics.drawImageWP(bg,0,0,6)

		if showLives then
			Graphics.drawImageWP(lives_font,lives_position[1],lives_position[2],8)
			Graphics.drawImageWP(lives_number,lives_position[1] + number_offset[1],lives_position[2],math.floor(mem(0x00B2C5AC,FIELD_FLOAT)/10)*28,0,28,32,8)
			Graphics.drawImageWP(lives_number,lives_position[1] + number_offset[1] + number_spacing,lives_position[2],math.fmod(mem(0x00B2C5AC,FIELD_FLOAT),10)*28,0,28,32,8)
		end
		
		for k,v in ipairs(SaveData.visible_chars) do
			
			if k > 1 and v == SaveData.visible_chars[1] then
				break
			else
				if v == SaveData.sel_char then
					Graphics.drawImageWP(chars,drawCoords[1] + (math.fmod(k -1,cols) -1) * spacing[1], drawCoords[2] + (math.ceil(k/cols) -1) * spacing[2], (SaveData.sel_char - 1) * 60, 0, 60,80,8)
				end
				
				if SaveData.chars_unlocked[v] == true then
					Graphics.drawImageWP(chars,drawCoords[1] + (math.fmod(k -1,cols) -1) * spacing[1], drawCoords[2] + (math.ceil(k/cols) -1) * spacing[2], (v - 1) * 60, 80, 60,80,7)
				end
				
				if SaveData.chars_unlocked[v] == false then
					Graphics.drawImageWP(chars,drawCoords[1] + (math.fmod(k -1,cols) -1) * spacing[1], drawCoords[2] + (math.ceil(k/cols) -1) * spacing[2], (v - 1) * 60, 160, 60,80,7)
				end
			
				if v == SaveData.char_hover then
					if SaveData.chars_unlocked[v] == true then
						Graphics.drawImageWP(cursor,drawCoords[1] + (math.fmod(k -1,cols) -1) * spacing[1] + cursor_offset[1],drawCoords[2] + (math.ceil(k/cols) -1) * spacing[2] + cursor_offset[2],8)
					end
				end
			end
		end
				
			for k,v in ipairs(SaveData.visible_chars) do
			
			if k > 1 and v == SaveData.visible_chars[1] then
				break
			else
				if showNames == true then
					if SaveData.chars_unlocked[v] == true then
						Graphics.drawImageWP(charnames,drawCoords[1] + name_offsets[1] + (math.fmod(k -1,cols) -1) * spacing[1],drawCoords[2] + (math.ceil(k/cols) -1) * spacing[2] + name_offsets[2],(v - 1) * lettersize[1] * 10,lettersize[2]*2, lettersize[1]*10,lettersize[2]*2,8)
					else
						Graphics.drawImageWP(charnames,drawCoords[1] + name_offsets[1] + (math.fmod(k -1,cols) -1) * spacing[1],drawCoords[2] + (math.ceil(k/cols) -1) * spacing[2] + name_offsets[2],(v - 1) * lettersize[1] * 10,0, lettersize[1]*10,lettersize[2]*2,8)
					end
				end
			end
		end
		
		if isOverworld then
			Graphics.activateOverworldHud(WHUD_NONE)
		end
		
	else
		if isOverworld then
			Graphics.activateOverworldHud(WHUD_ALL)
		end
	end
end

return characterselect

Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari