No input for game object on level1 collection

Hi
I am not a developer and I am creating a game off a template for space invaders. My game object in my Level 1 collection it doesn’t move and it appears its receiving no input. When my game object is placed in my main collection it moves in both my main collection and level 1 collection. I have searched the forums and found code that disables/hides my game object on my main collection but when enabled on the level 1 collection my game object still doesn’t move.

I have generated a link to a zip file of my project I would very appreciative if someone could have a look and help me with my problem.

https://drive.google.com/drive/folders/18z0ZcIYqqsUwYWdA05u9IZK8EqpYX1BO

I had a look at the code and it seems to me like a complicated mess, given that all it is supposed to do is display a few simple gui screens. I have not got round to learning how to code gui’s yet so I can’t follow it that well, so maybe I am totally wrong, however it looks like a plate of spaghetti, and I don’t think that it even contains a game. If you are a beginner looking to learn Defold, I suggest moving to a different tutorial. Side scroller and Walking Astronaut are good and you can get them from the load screen.

1 Like

I had just created a game object to see if it moves. I know the template I followed was a bit difficult, i was just wondering if you thought why it wouldnt move in the main collection and not the level 1 collection.

In level1_main.script the player is disabled, comment out.
Change the bootstrap to the level1 collection, it will then work.

Back to bootstrap from the main collection, comment out the 2nd and 5th:
msg.post(".", "release_input_focus") in main_menu.gui_script
Then it will work.

This is confusing, I guess the current collection and/or game object has swapped and so the dot reference has changed from under the feet of the script.

Hi

thanks for getting back to me, i really appreciate it.

“Back to bootstrap from the main collection, comment out the 2nd and 5th:
msg.post(”.", "release_input_focus") in main_menu.gui_script
Then it will work."

is all of this in the main_menu.gui_script? as i didnt have any information on the 2nd and 5th line there?

does the msg.post(".", “release_input_focus”) go into the function init(self) ?

Thanks for the continued help on this.

The bootstrap is in the game.project file, top entry; sets which collection runs at the start.

main_menu.gui_script has lots of lines with: msg.post(".", “release_input_focus”)
Comment out the 2nd and 5th of these, to make it work.
You could also add a print statement next to each (msg.post) to see which gets called (2nd&5th), output in the console window at the bottom of the IDE.

hello,

I was wondering if you could help me with another issue I am having with my game? I have created a GUI with a score and a timer and the timer works well and does what its supposed to. However the score doesn’t work when the enemy is hit by the bullet. I have tried to fix it but just can’t see anything wrong with it. I was wondering if you could have a look and point me in the right direction on how to fix it if possible?

Thanks

Chris

https://drive.google.com/drive/folders/1eTkAMpx4otCucLGrBlX44cgkJ9dcUdyn?usp=sharing

This should be posted as a separate thread.

Your enemy script consists of this:

function on_message(self, message_id, message, sender)
	if message_id == hash("trigger_response") and message.enter then
		--msg.post("interface#main", "hello")
		--sprite.play_flipbook("#sprite", "enemy_death", function()
			go.delete()
		--end)
	end
end

There is nothing in here that could possibly trigger the score to increase?

If I change it to this:

function on_message(self, message_id, message, sender)
	if message_id == hash("trigger_response") and message.enter then
		--msg.post("interface#main", "hello")
		--sprite.play_flipbook("#sprite", "enemy_death", function()
			go.delete()
		--end)
		msg.post("/GUILevel1#level1GUI", "increase_score")
	end
end

Then the score increments.


I thought what i had in here was enough to trigger it?
thank you very much

Yes, when the script receives a message. The issue was that neither the bullet nor the enemy messaged the script to ask for a score increase.

sorry mate I know this should be on another thread, on my level 1 I want to stop the level when either the score is reached or the time runs out. I have tried to do this but I am running into problems. I have tried to stop the collection and the player sprite but it doesn’t seem to be working.

Could you have a look and see what is going wrong or what I am missing?

Thanks

Chris

It’s a fair bit of work to download and get to grips with a full project. You say you’ve run into problems. What are they? Ideally you would post code snippets for what you are trying to achieve, any errors produced, etc.

when I have set my level 1 collection to stop when the time hits 0 or the score of 6 is reached it doesn’t work. Its the same when I have tried to disable the game object player but it continues.
Sometimes I have no errors and then I get the ones below:

ERROR:GAMEOBJECT: Component ‘/GUILevel1#player’ could not be found when dispatching message ‘disable’ sent from level1:/GUILevel1#level1GUI
ERROR:GAMEOBJECT: Component ‘/GUILevel1#level1_proxy’ could not be found when dispatching message ‘disable’ sent from level1:/GUILevel1#level1GUI

This is my Level1 script:

This is my Level 1 Gui script

and this would be my player script:

I have tried what I know and looked at the tutorials but I am lost.

Thanks

Chris

Just looking at your scripts, it’s a bit haphazard. Each one of them tries to disable player in on_message. You don’t check for message_ids in on_message which is a bit dangerous - it means the code will run no matter what message is received.

Have you tried interpreting the error messages? Component ‘/GUILevel1#player’ could not be found makes sense: you are trying to send a message to #playerfrom the GUI script but I don’t think player is a component of your GUI object.

I would advise you to step back and remove the game ending code you have added so far. Think about where it would be most sensible to place code relating to the level end, and work there. Don’t just indiscriminately write code everywhere.

4 Likes