Health system help

I have an issue with my message passing

i want to pass this to my health GUI but its saying it can’t find the instance.

		msg.post("/hearts/heartt.gui_script", "updatehealth",{new_health = self.player_health})

This is the ID of the script so i dont why its not working

/hearts/heartt.gui_script

/hearts/heartt.gui_script looks like the file path for your GUI script, not its ID. What’s the layout of the collection your GUI is in?

Then the full URL would be heart:/hearttt#heart (IDs and URLs are mostly interchangeable).

3 Likes

In heart, put this in the init() function:

print(msg.url())

That will tell you the URL to use when you send a message.

Your question is missing a few parts.

  1. What do you want to happen?
  2. What actually happens?
  3. What have you tried doing to fix it?

We are here to help but we can’t do every step, especially if you don’t provide enough context.

2 Likes

well i want it so that when the players health is equal to 80 one of the nodes which is a heart will be disabled.
The function removehearts isnt being called

How do you know that the function isn’t being called?

1 Like

the print in the removehearts function isnt being printed

That’s part of the reason why you should take your time and explain your problem in detail.

“I don’t think the function is being called because my print isn’t showing” should have been part of your original question.

Then I could’ve immediately told you that that isn’t necessarily the case. Your print comes after the conditional in your function. So the function may well be called.

What other reason might there be for the print not showing?

3 Likes

i tried and its working, but i would i pass a variable, self.player_health into my health script

Are you using a collection proxy to load the heart collection? If not, what other collection is it part of?

1 Like

the heart collection is part of the main collection

What is the layout of the main collection?

1 Like

That fine now but this is the code im having issues with

	if new_health == 80 then
		gui.set_enabled(heart0, disabled)

i want it so that my heart node is disabled and doesnt appear but i keep getting the error message

/hearts/heartt.gui_script:4: bad argument #1 to ‘set_enabled’ (NodeProxy expected, got nil)
stack traceback:
What is a nodeProxy

A NodeProxy is the type that’s returned by gui.get_node(). Assuming you have a node named “heart0”, the code to disable it is:

gui.set_enabled(gui.get_node("heart0"), false)
1 Like

could you explain the code if you dont mind just for future reference

This finds a node in your GUI scene with the ID “heart0” and returns it as a NodeProxy:

gui.get_node("heart0")

We then pass that to gui.set_enabled(), which takes a NodeProxy and a boolean as its arguments:

gui.set_enabled(gui.get_node("heart0"), false)

Giving it false will disable the node, and giving it true will enable the node.

You can also store the NodeProxy as a variable, which is helpful if you need to perform multiple operations on a node (like moving it, changing the color, playing an animation, etc.) or just to make the code clearer:

local my_node = gui.get_node("heart0")
gui.set_enabled(my_node, false)
2 Likes

That makes sense thank you

2 Likes