Deleted Node

Hi, I am trying to delete this GUI node when a variable is = 2, but once that happens the node is deleted but gives me iterative error message.


This disables me going to my menu with this message.

I am using a Lua module in order to make the variable “global” for all unloaded and loaded collections

HI, share your script please!

If it’s iterative you’ll probably deleting it more than once, so check it please, but yeah, if you could show as your gui_script, we could help :wink:

self.level2 = gui.get_node("2U")

if levelStage == 2 then
	gui.delete_node(self.level2)

if action.pressed and gui.pick_node(gui.get_node("tutorial"), action.x, action.y) then
	require "scripts.levelStage"
	msg.post("main:/controller", "pressed tutorial")
	levelStage = levelStage + 1
	print(levelStage)

	if levelStage >= 3 then
		levelStage = 3

	end
end

I think this is a syntax error. You are missing an ‘end’ between the node delete and the action conditional.

if levelStage == 2 then
	gui.delete_node(self.level2)
end

If this compiles then you probably have an extra end somewhere further down that is in the wrong place.

function on_input(self, action_id, action)
require "scripts.levelStage"
if action.pressed and gui.pick_node(gui.get_node("menu"), action.x, action.y) then
	msg.post("main:/controller", "menu pressed")
end
if action.pressed and gui.pick_node(gui.get_node("1"), action.x, action.y) then
	msg.post("main:/controller", "level 1 pressed")
	print(levelStage)
end
if levelStage >= 2 then
	gui.delete_node(self.level2)
	if action.pressed and gui.pick_node(gui.get_node("2"), action.x, action.y) then
		print(levelStage)

– script 2

if action.pressed and gui.pick_node(gui.get_node("tutorial"), action.x, action.y) then
	require "scripts.levelStage"
	msg.post("main:/controller", "pressed tutorial")
	levelStage = levelStage + 1
	print(levelStage)

	if levelStage >= 3 then
		levelStage = 3

	end
end

sorry i should of included more code, here is the code that is relevant to the problem(i think), if the problem cannot be identified i’ll be glad to share the file

Perhaps someone else can spot the problem already but I would say it’s hard to figure out with just two partial snippets (which one triggers the error?). So if you could share the full context plus highlight the exact line that causes the error then that would be useful.

1 Like

There really isn’t much to but these two snippets I got here and the error line is

		gui.delete_node(self.level2)

and levelStage is stored in a Lua module with the value 1

The context is that I am incrementing the levelStage once level1 has been complete and if its greater then 1 then level 2 is available which then deletes a lock node (which is just a image of a lock) and also enables access to the level2 GUI node, but when I do this the deletion of the lock node seems to be iterative and then breaks the whole game as when I try go to the menu it instead leads me to another collection (level1)

Is the line where you delete in on_input? If so then it will fire for all kinds of input (lots of times even if you just move your mouse). So the node will be deleted early on and you’ll be trying to delete it again and again.

You’re not checking for an action, just that levelStage >= 2. That part will execute any time there is any input.

2 Likes