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