Collection proxy help

Hey, theres a post in the defold tips about splash screens and main menus and im trying to learn how to impliment that before a player gets to the game. They click on the screen, then it loads the collection that has all the game workings in it.
I get this error when I click however

ERROR:SCRIPT: main/splash.script:27: The socket ‘main’ could not be found.
stack traceback:
[C]: in function ‘post’
main/splash.script:27: in function <main/splash.script:23>

this is the code that went along with it;

function init(self)
– Add initialization code here
– Remove this function if not needed
msg.post(“.”, “acquire_input_focus”)
print(“Init splash…”)
end

function final(self)
– Add finalization code here
– Remove this function if not needed
end

function update(self, dt)
– Add update code here
– Remove this function if not needed
end

function on_message(self, message_id, message, sender)
– Add message-handling code here
– Remove this function if not needed
end

function on_input(self, action_id, action)
– Add input-handling code here
– Remove this function if not needed
if action_id == hash(“click”) and action.released then
msg.post(“main:/loader#script”, “goto_main_menu”)
print(“Going to main menu…”)
msg.post(“.”, “release_input_focus”)
end
end

function on_reload(self)
– Add input-handling code here
– Remove this function if not needed
end

And also I was reading through the tutorial for collection proxies
“The loading and unloading of the two collections is controlled by a game object called “loader” that we put in our main collection “worlds”. We configure the game to automatically load the “worlds.collection” file at startup (see Project settings documentation for details). The collection “worlds” will hold the “loader” object as well as the GUI elements that allow us to move our character around”
This was done by opening the text editor and changing the [bootstrap] yes?

Did you set splash.collection as your bootstrap? Did you rename the name of splash.collection? Not the filename, its name when you have it open in editor / open in a text editor. Its default name is default not main.

So I can better understand how the collection proxy works I created a new file with just your example project. I Didnt change the names of anything. when it run it, it says
WARNING:RESOURCE: Resource not found: /main/splash.collectionc
or
WARNING:RESOURCE: Resource not found: /default/splash.collectionc

You forgot to include the screens folder

/main/screens/splash.collectionc

By the way I was asking not telling you to set it as bootstrap. Trying to understand your setup.

1 Like

Ah yeah. Added that and added the key binding for clicking, now I get this error;
main/screens/splash/splash.script:27: in function <main/screens/splash/splash.script:23>
ERROR:SCRIPT: main/screens/splash/splash.script:27: The socket ‘main’ could not be found.
stack traceback:
[C]: in function 'post’
main/screens/splash/splash.script:27: in function <main/screens/splash/splash.script:23>
ERROR:SCRIPT: main/screens/splash/splash.script:27: The socket ‘main’ could not be found.
stack traceback:
[C]: in function 'post’
main/screens/splash/splash.script:27: in function <main/screens/splash/splash.script:23>
similar to the one i ran into in my original project

Open splash.collection and change the name from default to main, or change code to say default instead of main / rename both.

I’m still assuming this is what is wrong but I may be wrong.

changed it, it says it cant be found now.

What’s the full error message?

Zip project, upload here and I’ll look at it.

1 Like

m.zip (375.1 KB)
Thanks, not sure whats up with it.;

This doesn’t look right. Are you always editing your collections in text mode?

component: "/default/screens/splash/splash.gui"

is the path on disk and it doesn’t seem like you have a folder named default in the root of your project. And when @Pkeod said “change from default to main” he meant the name of the collection as set in the properties window when you have opened a collection and selected the root of the collection, not the folder name.

You must not confuse the location on disk with how you organise your collections and game objects in the scene graph.

3 Likes

Thanks, Sorry I come from a web coding background so i’m still adjusting to this.
When it says

ERROR:GAMEOBJECT: Instance ‘/loader’ could not be found when dispatching message ‘goto_main_menu’ sent from main:/go#script

What is an “instance”? I’m guessing it means script because this is the line it talks about?

	msg.post("main:/loader#script", "goto_main_menu")

An instance is a term for for one existing version of “something”.

When you create an object in the editor, you can view that as a blueprint of your object. When you run the game, and your object comes alive, it becomes an instance. If you have two copies of your object, they are two instances of the same blueprint, with individual attributes.

A good example of this, is how the factories work. They use a gameobject as a blueprint, but every object they create, is an instance of that object. That is whats called instantiating.

The script is the brain of your object, but each instance has its own brain.

4 Likes

This error means that in the collection named “main” there is no game object with id “loader”.

3 Likes

Thanks you very much for helping me understand that, makes it alot simpler now :grinning:

2 Likes

What if it’s in the main collection, but its in there inside of another collection?thats how mine is setup

1 Like

Ok, but if it’s set up in a different way then you can’t post a message to it using msg.post("main:/loader#script", "goto_main_menu"). You need to change the url you are using in msg.post() such that it reflects the actual structure of your game objects and collections.

Perhaps you could post a screenshot of the game object hierarchy?

2 Likes

not inside of a collection anymore.

Ok, so the URLs to the different scripts are:

main:/go#gui – ULR to splash.gui
main:/go#script – URL to splash.script
main:/loader#loader – URL to loader.script

This means that if splash.script wishes to to post a message to the loader.script you can do either:

msg.post("main:/loader#loader", "my_message") -- absolute path
msg.post("loader#loader", "my_message") -- relative path

And if you look at messages between splash.script and splash.gui the relative URL is even simpler:

msg.post("#gui", "my_message") -- relative path

1 Like

okay so;
main:/go#gui – ULR to splash.gui
Main is the ID Of the collection, go is the Game object and inside the game object is the gui script which has an ID of gui
so then this

local function load_main_menu(self)
msg.post(“main_menu:/go#script”, “load”)
end

local function unload_main_menu(self)
msg.post(“main_menu:/go#script”, “unload”)

Should work if theres a collection with the ID name of “main_menu”, inside of that is a game object with the ID of go, and attached to that is a script with the ID script?

Because when I did that I get the error

WARNING:DLIB: Failed to send announce message (-22)
DEBUG:SCRIPT: Going to main menu…
ERROR:SCRIPT: main/screens/loader.script:2: The socket ‘main_menu’ could not be found.
stack traceback:
[C]: in function 'post’
main/screens/loader.script:2: in function 'load_main_menu’
main/screens/loader.script:39: in function <main/screens/loader.script:35>
WARNING:DLIB: Failed to send announce message (-22)

Hmm, I think it would be best if someone took a look at your project to figure out what’s wrong. I’m on vacation until Wednesday next week, but maybe @sicher or @sven could take a look?

1 Like