Hello its again, i’m trying to post the value for my players health into the GUI script but i keep getting “nil” returned whenever i try to do anything with that value. I had an issue with the message recipient but i think thats ok now. I’ve tried changing the value thats being sent to just a regular integer and got an error saying “table expected, number received”.
This is the player script:
function on_message(self, message_id, message, sender)
if message_id == hash("trigger_response") then
print("collide")
-- checks if enemy and player collide
if message.enter then
-- only damage player when entering enemy radius
take_damage(self, 5)
msg.post("health bar", "health_update", {new_health = self.health})
-- send current health value to gui
end
end
end
This is the gui script:
local function update_health(self, health)
print(health)
end
function on_message(self, message_id, message, sender)
-- check if health message recieved
if message_id == hash("health_update") then
-- pass new health into update health
update_health(message.new_health)
end
end