The path component of a URL must always be expressed as an absolute path. If we want to construct a URL ourselves, either with the msg.url() function or by typing the URL in string form, we must give an absolute path. So:
thats not mine, its from the tutorial. Take the frog tut for example:
elseif message_id == hash("contact_point_response") then
-- check if we received a contact point message
if message.group == hash("danger") then
-- Die and restart
play_animation(self, hash("die_right"))
msg.post("#collisionobject", "disable")
go.animate(".", "euler.z", go.PLAYBACK_ONCE_FORWARD, 160, go.EASING_LINEAR, 0.7)
go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, go.get_position().y - 200, go.EASING_INSINE, 0.5, 0.2,
function()
msg.post("controller#script", "reset") -- this alone works fine
msg.post("/level/life#script", "reset") -- adding this makes the error show up.
When the frog dies, I want the message to be sent to my life script telling it that I just died
the life script is here;
function init(self)
self.life = 4
end
function on_message(self, message_id, message, sender)
if message_id == hash(“reset”) then
self.life = self.life - message.reset
if self.life <= 0 then
go.delete()
msg.post("/level/controller#script", “lives”)
end
end
end
It’s saying it cant find it though its inside of level folder.
Yes, the folder structure doesn’t matter. Ids and how they relate to each other is of importance. So it all depends on where your life script is located. If you could share a screenshot of how you have organised your game objects and scripts then it will be easier to help you.
What I’m doing is when the frog dies, it sends a message to the controller script this way;
msg.post(“controller#script”, “reset”)
msg.post(“controller#script”, “resetscore”
Reset message is sent so the frog resets when it dies, and the score reset is so the score resets, instead of starting over once a coin is collected. like so;
if message_id == hash(“resetscore”) then
self.score = 0
msg.post(“hud”, “set_score”, { score = 0 })
–lives test
elseif message_id == hash(“set_lives”) then
local l = gui.get_node(“life”)
gui.set_text(l, message.life)
–end lives test
set_lives(self, message.lives)
end
OK, so you are saying that when this line is run you get an error:
msg.post("/level/life#script", "reset")
Correct?
So the question is from which script is the above line of code called and where is the life script located? And now I’m not talking about location in the folder structure on disk. I wan’t to know to which game objects the two scripts belong and in turn which collections the game objects belong to? Have you read up on the section on Addressing and URLs? You can always do print(msg.url()) to show the absolute path of a script.
EDIT: Nevermind, I had the wrong scrip open, @My original post
The hero script sends a message to the life script. the life script is inside of level collection as is the hero script. the life script is attached to the hero Go.
The project file stucture thet you ser in the Project Explorer has no impact on the paths/urls:s. The only thing that matters is in what collection game objects has been placed.
Can you post a screenshot of your main collection outline?
When you try to send a message to “/level/life” you address a game object “life” in the collection “level”. I see that you have two scripts in “hero”, with id “script” and “script1”
If you want to direct your message to “script1” from “script” in “controller”, do:
msg.post("hero#script1", "hello")
Since “controller” and “hero” lives at the same level in the collection hierarchy you don’t need to specify “/level/hero#script1”. Addresses that begin with “/” are absolute, from main’s root but addresses can be relative as well, like in the example I gave.