In a game im making ive got a tile which when the player hits it it displays the time the level was completed in on a gui that is overlaying the game. This worked as when the player is playing the game the only node in the gui had nothing in it so it appread as if there was nothing there. But i was wondering how i could add a background to my gui that only shows on the screen once the player has finished the level. Is this even possible?
You can always have the background node in your gui and let it start hidden (there is a checkbox to hide the node in the properties panel) and then use gui.set_visible(node, true) to show it.
I did this but got a strange error:
function on_message(self, message_id, message, sender)
if message_id == hash("time") then
gui.set_text(gui.get_node("textTimer"),message["timer"])
gui.set_text(gui.get_node("textLevelComplete"), "LEVEL COMPLETED IN...")
gui.set_visible("boxExit", true)
end
end
do you know how i should fix this, or should i just put this in the bugs forum
I managed to sort it by fetching the node before i set it to visible by doing:
gui.set_visible(gui.get_node("boxExit"), true)
That’s right, that is what the error indicated by stating “bad argument #1 to ‘set_visible’ NodeProxy expected, got string”. See documentation here.
It’s maybe a bit hard to understand, but the error message actually contains all the information you need!
First it says:
bad argument #1
Functions take arguments, like this:
function(argument1, argument2)
So you know the error has something to do with the first argument of a function you call on line 5. The error message actually names the function:
‘set_visible’
It then tells you what it expects to receive, but what it got instead:
NodeProxy expected, got string
So it expects the output of gui.get_node() but it got a string instead (the name of the node).
Error messages can be hard to grasp sometimes but it pays to try and understand them.
Note that the bugs forum is for actual bugs in the Defold engine or editor. This would not be relevant for that.
Cheers dude managed it and got a button working that takes the player back to the main menu, thanks so much!!!