I’m creating an enemy (Spider_Bot) that moves left and right and at some point (for example, every 4 sec.) it will shoot laser beam (done by creating the laser object and change its height to fit on the battlefield.) then it will gone after another 4 seconds. It works perfectly fine but its only working on one enemy (Spider_Bot) only.
I try to use for each object but it’s not working. I know there’s something that I have done wrong so I hope someone can help me with it. Thanks in advance!
Maybe try "for all objects"
Or try placing a for each laser beam in or outside of the for each spider bot
there are timer for objects too.
so each spider can have its own timer.
then you should give each spider a unique id (variable)
when the timer of spider >4, create laser at spider pos and do spider id to the variable id of laser.
when timer of spider >8 and id of spider = id of laser delete laser and reset timer of spider.
that way a for each should not be needed.
I try what you said but again, it works only on one spider bot. I try with and without for each object but it’s not working. Hope you can help me again. Thanks in advance!
Your problem sounds mighty similar to my issue with trigger once and repeat blocks. If it is the same, it’s because of the way that the Trigger Once works (and has a bug, IMO). My original post also has a work around too, which you could adapt to your situation.
I read to forum but I don’t know exactly what it means because I’m new to GDevelop. Can you tell me what exactly what I need to do to fix it?
i tryed it and it seems object timers did not work the way i was assuming.
also was a little toublesome to actually get them consistently do what there supposed to do.
but i found a working solution:
each spider needs to have a unique id.
and the variable laser is needed,
because, as MrMen sad, timer condition with trigger once, does not reset the trigger once, once the timer falls below its condition (omg what a sentence)
@FutureGameDeveloper, looking at your second event snippet, I wonder if you need the “Trigger Once” condition? You’re setting the Attack variable if the first set of conditions are met, so it that won’t get triggered the next time round. And if the second event’s conditions are met, then the object is deleted and won’t exist any longer.
@Slash, that last sentence should be made illegal!
So I copy the commands you use but the problem is still there. It only works on one Spider_Bot. I really need to fix this because I need this to almost all of my enemies where the goal is to make it work to all enemies and not only one. Hope you can help me further because I really need this to work.
@FutureGameDeveloper, try your second attempt without the trigger once :
I try to remove trigger once. What happens is that at first, first spider bot fires laser. then in the second time, the other spider bot fires laser at a short time then it stops then the first spider bot fires again. In short, it doesn’t work at the same time.
I’ve had a closer read of your events, and the second one isn’t correct - in it you are deleting laser. But you are not specifying which laser in your conditions. So it’ll be deleting a seemingly random laser object. You need to link the laser to the spider_bot, or put a timer on the laser.
keep the trigger once. thats not the problem and helps.
you need to give the instance of your spider in the scene editor a unique id.
one with id1, next id 2 3rd id 3 and so on. so do not give them the variable inside the object editor, but scene editor.
edit: nvm, the variable attack is fine, i was thinking of something else.
I finally made it!
I watched a video on YT that shows exactly what I need to do! It only needs “For each object” and link the enemy and the bullet. Now I can create enemies that do many things like an enemy that shoots in 4 directions simultaneously. Thank you so much!