For Each Object Problem or Something Else?


#1

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!


#2

Maybe try "for all objects"🤷


#3

Or try placing a for each laser beam in or outside of the for each spider bot


#4

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.


#5


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!


#6

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.


#7

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?


#8

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)


#9

@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! :smiley:


#10


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.


#11

@FutureGameDeveloper, try your second attempt without the trigger once :


#12

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.


#13

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.


#14

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.