New to Defold...Stuck on the colorslide tutorial

I am running through the colorslide tutorial because I am trying to learn how to build start screens and selection screens. Like the tutorial, I want the start button to be pressed and the level selection to appear. In my main.collection folder, I have a game object that contains both the start gui and the level select gui. The level selection screen is supposed to be hidden until the user clicks the button but when the project is built, both screens appear on-top of each other therefore the code isn’t hiding the screen. What am I missing? Much thanks.

The code that hides and hows the level selector is in ”level_select.gui_script”

function on_message(self, message_id, message, sender)
    if message_id == hash("show_level_select") then                     -- [2]
        msg.post("#", "enable")
        self.active = true
    elseif message_id == hash("hide_level_select") then                 -- [3]
        msg.post("#", "disable")
        self.active = false
    end
end

Check that the messages arrive correctly (by adding print() or setting a debugger breakpoint). The init() function of the script should send a ”hide_level_select” message. If nothing is sent, check that the script is added to the GUI.

2 Likes

I also realized that the back button does not function but I do not receive any console errors upon building the current game. It leads me to believe that the level_select script is not running at all. It is assigned to the level_select.gui and the gui is added to the same game object as start. Without any console errors I am not sure why the script seems to not function at all

Put a print in init() to verify that it runs.

1 Like

Thanks! It appears the script isn’t running. The script is assigned to the correct gui and the gui is in the correct game object (same place as the start gui). What are next steps to try to get the script running. The start script seems to work fine…it is just the level select script that doesnt appear to be running. Thanks for the help!

Do you have any errors in the console?

Post a screenshot of the setup or share the project here.

Here is a small project where I’m practicing the techniques from the tutorial. Essentially the level_select script doesn’t appear to be running. I followed the tutorial closely and the scripts are pretty much the same from the tutorial until I can start to play around with the interface more. Much thanks if you are able to spot what I am missing. I have included snippets of both scripts, the main.collection outline, and the screen I get after building the game.

collection

The start script is missing an end statement to finish the definition of on_message, right before on_input.

Don’t you get an error in the console when running?

Exactly. That should generate an error.

Apart from some indentation issues in the start script, I don’t see anything directly wrong with the code. (Next time, paste a snippet of the code directly in the forum post. It’s way easier to read and help out then)

You can easily verify that a script is running by either adding a print("hello from", msg.url()) in the init function. Or by setting a breakpoint in the code, and then run with the debugger.

I wonder if the issue isn’t that the level select gui/script isn’t running.
I think that the start screen isn’t hiding?

Also, what is in the /main/Gui.collection ? Is that showing the entire time?

1 Like

The tutorial did not have me put another end statement for the function on_message.

/main/Gui.collection does not contain anything.

I also ran the print function on both scripts and both display the function in the console so I’m not sure why the screens overlap each other.

Please zip the entire project (exclude build and .git folder) and share it so I can take a look.

It does not upload the zipped file…it loads to 1% then disappears without an error message

Can you share it some other way then? You can also e-mail it (bjorn.ritzl@king.com).

I sent the zip to the provided email.

Thanks. I noticed a few things:

You have duplicates of both level_select.gui and start.gui in your main collection. I guess this isn’t intentional?

The level_select.gui_script has on on_message function with three s:

function on_messsage(self, message_id, message, sender)
	if message_id == hash("show_level_select") then

Ah. Should I keep them in the go game object or the guis game object. The tutorial had me put them in the guis object. Also on_message function was also from the tutorial. Did I not interpret it correctly?

Well I got rid of extra “s” and the level selection is hidden like it’s supposed to be. Upon hitting play though the screen just goes black so it solved 50% of the issue haha.