Problem with ‘complete_function’ when animating scale of gui node [SOLVED]

I’m having a problem animating a gui node for an in-game menu, specifically with the ‘complete_function’ I’ve defined, which doesn’t seem to recognise the node sent in its parameter.

The animation when opening it works fine, but the closing part throws up an error.

My code is as follows:

function init(self)
	msg.post(".", "acquire_input_focus")

	local menu_panel = gui.get_node("menu_panel")
	gui.set_scale(menu_panel, vmath.vector3(0, 0, 0))
	gui.set_enabled(menu_panel, false)
end

local function gui_disable(self, gui_node)
	gui.set_scale(gui_node, vmath.vector3(0, 0, 0))
	gui.set_enabled(gui_node, false)
end

function on_input(self, action_id, action)

	local menu_panel = gui.get_node("menu_panel")
	local menu_enabled = gui.is_enabled(menu_panel)

	if menu_enabled == false then

		if action_id == hash("Menu") and action.pressed then
			gui.set_enabled(menu_panel, true)
			gui.animate(menu_panel, "scale", 1.0, gui.EASING_OUTBACK, 0.25, 0, nil, gui.PLAYBACK_ONCE_FORWARD)
		end

	elseif menu_enabled == true then

		if action_id == hash("Menu") and action.pressed then
			gui.animate(menu_panel, "scale", 0, gui.EASING_INBACK, 0.25, 0, gui_disable(menu_panel), gui.PLAYBACK_ONCE_FORWARD)
		end
	end
end

The error message I’m getting is…

ERROR:SCRIPT: main/gui/game_menu.gui_script:10: bad argument #1 to 'set_scale' (NodeProxy expected, got nil) 

stack traceback:
  [C]:-1: in function set_scale
  main/gui/game_menu.gui_script:10: in function gui_disable
  main/gui/game_menu.gui_script:29: in function <main/gui/game_menu.gui_script:14>

Thanks in advance for any responses!

try

gui_disable(self, menu_panel) --> add self before the gui_node 

on the on input function

Thanks Asatte, that’s cleared up the error.

However, it doesn’t animate the closure of the menu- it just makes it disappear.

I thought the ‘complete_function’ was something that it ran after the animation has finished.

Okay, I’ve sorted it!

After looking (more carefully!) at the examples on the API, it seems you don’t have to send any parameters to the function, so the relevant line now reads:

gui.animate(menu_panel, "scale", 0.0, gui.EASING_INBACK, 0.25, 0, gui_disable, gui.PLAYBACK_ONCE_FORWARD)

I now have a very satisfying bouncy popup menu in my game :slight_smile:

1 Like