Timer to Spawn Object Every X Seconds

Get help using Construct 2

Post » Fri Jan 10, 2014 12:41 am

Have tried to figure this out using the timers here:
https://www.scirra.com/tutorials/450/timers
but have not had any success. In short I am wanting to spawn an object on a layout every say 30 seconds. However at the start of a layout I want to start over and thus the construct statement "every x seconds" wont work as that is a revolving clock.

So I created a global variable "timer=0"
Add 1 to timer every 1 seconds
Set timer to 0 at the start of layout

Now my only question is how to get it to spawn the object every thirty seconds using my timer variable above?

I tried when timer/30 is equal to integers 1-50 but int doesnt work that way, I was basically trying to get it to only spawn when it was a multiple of 30. Any ideas much appreciated.kenn2014-01-10 00:44:34
B
14
S
2
Posts: 39
Reputation: 689

Post » Fri Jan 10, 2014 1:13 am

That tutorial is out of date. Use the new Timer behaviour.

TimerExample.capx
ImageImageImage
B
71
S
21
G
229
Posts: 3,686
Reputation: 128,336

Post » Fri Jan 10, 2014 1:51 am

To get objects to spawn every 30 seconds you could try:

Every 1 second - add 1 to (Variable)"Timer"

If (Variable)Timer is greater than 30 - set value to zero

Then on (system) on end of layout - (system) reset global variables
B
6
S
2
Posts: 151
Reputation: 1,366

Post » Fri Jan 10, 2014 1:54 am

@EyezWidee you can also add 1 every second by doing:

Every Tick: Add 1 * dt to Variable "Timer"

The reason for that is to make it work even if the game gets laggy (dt always adds up to 1 every second). It's used in most of the built-in plugins to keep them smooth.

Ashley wrote a good tutorial on it too here: https://www.scirra.com/tutorials/67/delta-time-and-framerate-independenceJayjay2014-01-10 01:54:54
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit Dropbox is a pile of trash and if you need my old files PM me! :)
B
116
S
40
G
17
Posts: 2,197
Reputation: 19,433

Post » Fri Jan 10, 2014 2:46 am

Okay thats actually pretty interesting I didnt know that, I try to avoid using every tick with variables feels like it hinders the performance especially when it involves webstorage. But I'll deff give that try also.
B
6
S
2
Posts: 151
Reputation: 1,366

Post » Sat Jan 11, 2014 12:29 am

Both are excellent answers, thank you I greatly appreciate it.

One questions for clarification does the new timer behavior also work on dt so in the event the game was lagging it would behave correctly?
B
14
S
2
Posts: 39
Reputation: 689

Post » Sat Jan 11, 2014 1:38 pm

@Kenn

Var = Difficultly

Every X Second= add 1 to difficulty

System Var Difficulty is greater than 5
"Add another condition"
System Var Difficulty is less than than 30
"Sub event"
Every 1 second

Action create object (enemy) (How and where you want)


https://www.dropbox.com/s/w1lgjrif7nneu69/Var-Spawn1.PNG


Here is a link to how I have mine set up (works for me)ALLMarkMade2014-01-11 13:40:28
Check out my latest game RAPID-TAPIT. Get your Fingercise on with this one. A steady Tap is all you need to score points. Lift a finger and see what you can do...

Image

ALLMarkMade Designs
B
32
S
15
G
3
Posts: 356
Reputation: 5,269

Post » Sat Jan 11, 2014 3:08 pm

Yes, Timer uses dt.
ImageImageImage
B
71
S
21
G
229
Posts: 3,686
Reputation: 128,336

Post » Sat Jan 11, 2014 6:39 pm

as another alternative

var nextTime
var timedelay

On start of Layout
nextTime = time + timedelay

Event: nextTime <= time
do your creation
nextTime = time + timedelay
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Tue Jan 14, 2014 1:30 am

Thanks everyone for the input. Glad that the timer uses dt, ultimately I went with the timer plugin and found that I could add quite a few variations and variables leveraging what was already built into it. Thanks again.
B
14
S
2
Posts: 39
Reputation: 689

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests