How do I use "for each" in "every x seconds" ?

Get help using Construct 2

Post » Thu Apr 16, 2015 7:01 pm

Message: Fireche can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hi, i want every 5 seconds to spawn 10 bullets. Each with a time-difference of 0.1 seconds.
I figured the easiest way how to do it, is the following: http://prntscr.com/6ujkhy

But for some reason it simply spawns the bullet only every 5 seconds. I know there are other ways solving it..but why does my solution not work? *confused*

thank you!
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Thu Apr 16, 2015 7:08 pm

Off the top of my head (away from my desktop at the moment), my suggestion would be to add the Function object to your project, and create a function that is called as an action in that "every x seconds" event. Then, in the function event being called, you place the code for your For loop.
ImageImageImageImage
B
62
S
19
G
51
Posts: 633
Reputation: 30,826

Post » Thu Apr 16, 2015 7:14 pm

Fireche wrote: Image


search for wait in loops..
.. you spawn 10 bullets every 5 sec..in one tick..on same x.y..check in debugger...

capx:
http://s000.tinyupload.com/index.php?fi ... 6479947910
Last edited by korbaach on Thu Apr 16, 2015 8:57 pm, edited 1 time in total.
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Thu Apr 16, 2015 8:06 pm

I guess you could try the giving something the timer-behaviour and do it like this:

create global variable "numberofbullets" and set it to 0

every 5 seconds
> system set variable "numberofbullets" to 10
>start timer "bullet" for 0.1 seconds

on timer bullet
>call function "shoot"

on function shoot -
> spawn bullet
> system subtract 1 from variable numberofbullets
- system compare variable "numberofbullets" > 0
> start timer "bullet for 0.1 seconds

But the loop thing is obviously much better.. haha
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: cb130felix, Google [Bot], JDebstup, Kermad, Lancifer, piddlyPoo and 5 guests