Node used in the wrong scene

Hi everybody!

Have such problem, read some posts about it but still don’t know what’s wrong.
Have a main scene, where fill table with callbacks and on some game actions try to call this callbacks and get the error “Node used in the wrong scene”.

The problem is that you are using a gui.* function on a node that doesn’t belong to the same gui scene as the script that is calling the gui function. Here’s an example with two .gui files with a .gui_script each and one .lua file:

  • The Lua module keeps a list of gui nodes and it provides a function for setting the color of all nodes:
-- module.lua
local M = {}

local nodes = {}

function M.add_node(node)
	table.insert(nodes, node)
end

function M.set_color(color)
	for _,node in ipairs(nodes) do
		-- This may trigger "node used in the wrong scene!"
		gui.set_color(node, color)
	end
end

return M
  • Here’s one gui script that adds a node to the module:
-- foo.gui_script
local module = require "module"

function init(self)
	module.add_node(gui.get_node("foo"))
end
  • And here’s another gui script that adds a node to the module:
-- boo.gui_script
local module = require "module"

function init(self)
	module.add_node(gui.get_node("boo"))
end

Now, what happens if we call module.set_color(vmath.vector4(1,0,0,1) from a gui script or some other script file? If the list contains nodes from multiple gui files or if we call it from a script file we will encounter the “Node used in the wrong scene” error.

I don’t know enough about how you have structured your code but it is certainly the case that you have a mixup of your gui node references!

5 Likes

Oh, now I understood… So I can’t call gui functions from another scripts…
Thank you!

1 Like