More explanation

reading through the message passing tut here http://www.defold.com/manuals/message-passing/
and came across this

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:

msg.post(“default:/hearttree/tree#script”, “grow”) – OK!
msg.post(“default:tree#script”, “grow”) – ERROR!

Omitting the root front slash result in an error message because there is no game object with absolute path “tree”.

ERROR:GAMEOBJECT: Instance ‘tree’ could not be found when dispatching message ‘grow’ sent from default:/hearttree/pot#script

Having a hard time understanding what this passage means. Ive fallen into the same issue as well, so maybe understanding this will help.
Thanks

What’s the name of your main collection? It’s probably “main” and not “default” edit your main.collection with a text file and see its name there.

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.

Post your project here in a zip and I’ll take a look to see what is wrong.

The folder name is totally irrellevant. Only the id:s of collections, game objects and components matter.

1 Like

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.

1 Like

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
 --   elseif message_id == hash("lives") then
--    self.life = self.life - message.reset
--    msg.post("hud", "set_lives", { life = self.life })

the Hud part of the code is;

–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.

1 Like

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.

ERROR:GAMEOBJECT: Instance ‘/level/life’ could not be found when dispatching message ‘resetscore’ sent from main:/level/hero#script

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?

2 Likes

I was trying to understand what the tut was saying, kinda got confused with it though.

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.

4 Likes

Thank you very much, it worked.

There’s a brand new manual on message passing that I hope explains all this better than the old one: http://www.defold.com/manuals/message-passing/

5 Likes

That new manual is fantastic . Great addition to the docs.

3 Likes

Thanks a lot! Hope it will be of help.

3 Likes