Can't use gui functions in gui_script scope (SOLVED)

I’m not sure if that is intended but,
if I try to call a gui function in a gui_script file but not inside any function like this:

local box_node = gui.get_node("box_node")

function init (self)
  gui.animate ( box_node, ... )
end
function update(self, dt)
  gui.animate ( box_node, ... )
end

I get this error :

ERROR:SCRIPT: You can only access gui.* functions and values from a gui script instance (.gui_script file)

I found a way around like this :

local my_nodes = {}

function init (self)
  my_nodes.box_node = gui.get_node("box_node")
  gui.animate ( my_nodes.box_node, ... )
end
function update(self, dt)
  gui.animate ( my_nodes.box_node, ... )
end

But this gives me the same error:

local my_nodes = { box_node = gui.get_node("box_node") }

Shouldn’t we be able to use gui functions inside a gui script even tho they are not inside a function ?

No you are not able to use gui.* or go.* functions outside of the callstack of the lifecycle functions.

BTW, you should use self to store a reference to the node:

    function init (self)
      self.box_node = gui.get_node("box_node")
      gui.animate ( self.box_node, ... )
    end
    function update(self, dt)
      gui.animate ( self.box_node, ... )
    end
1 Like

Yeah self, how did I forget it ?? Maybe it’s time for a little break :slight_smile:
Thanks for your time.