Every X Seconds + Restart Layout

Get help using Construct 2

Post » Thu Feb 13, 2014 9:15 pm

I have the following issue:

The "every x seconds" command does not seem to reset, if I restart the layout.

I have an object, which is created after every 2.5 Seconds. So if I restart the layout, sometimes two instances of this object are generated on top of each other.

Is there a way to reset the after "every x seconds" command?


Thanks in advance.

B
10
S
2
Posts: 135
Reputation: 1,090

Post » Thu Feb 13, 2014 9:23 pm

Every X seconds is based on the system timer, not the running time of a layout.

It would be better to either use the Timer behavior or create your own timer by creating a global variable and adding dt to it every tick. Then you can reset it to 0 when you want.
B
101
S
32
G
11
Posts: 1,552
Reputation: 21,667

Post » Thu Feb 13, 2014 9:25 pm

Okay I also considered the variable on every tick solution. But I thought it whould be more demanding than the every x seconds command.

So I will try the timer behavior. Thank you.


Edit:

Thanks it works like a charm.Alyra Games2014-02-13 21:31:17
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Sun Mar 23, 2014 5:09 am

Hi guys, I know this is an older post, but it is my exact problem and I don't really understand the solution. I get the idea of the Timer behavior or using a delta timer Global Variable, but I don't just don't get how to implement it. The Timer behavior is related to an object and right now it is the System spwning my objects so I don't quite get that part. As for my own Timer, where/how do I actually make the repeatable counter.

My problem is that right now the System is creating the objects for me and from what I under the object itself needs to create... itself?

Thanks!
B
6
S
2
Posts: 18
Reputation: 563

Post » Sun Mar 23, 2014 6:26 am

you can create an event "every X seconds", and just as it states, every x seconds it will trigger and start counting again. so in the case of a spawner, that should work,

the problem Alyra had, was that he was restarting the layout and the "every X command" is not meant for that use.
B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Post » Sun Mar 23, 2014 6:41 pm

Thanks for your quick reply! Actually I'm having this problem. My spawners are set at Time >= 4 sec then every 3 seconds spawn. The problem is that when I restart the layout for a new game it does not wait and they immediately start spawning things!
B
6
S
2
Posts: 18
Reputation: 563

Post » Mon Mar 24, 2014 12:21 am

that is because when you restart the layout, the game has already been playing for several seconds.

You need to make a custom timer.

1) make a timer variable and set it to a value (like 240)
2)every tick, while timer variable es greater than 0, substract 1 (60 ticks in a seconds, so it should take 4 seconds to subtract all 240)
3)when timer variable is equal to 0 = spawn every 3 seconds.
4) enjoy.
B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Post » Mon Mar 24, 2014 12:34 am

yeah using a timer is your best option... you can start and restart them whenever you want... makes things a lot easier...

just make an empty game object, make it invisible and give it the Timer Behavior.
B
97
S
32
G
16
Posts: 1,199
Reputation: 16,680

Post » Thu Mar 27, 2014 7:40 am

Ahhhh! Thanks a lot Sargas, that does make a lot more sense now! So I should just create a Text Object with a Timer and use that to control my stuff. Since I have multiple different timers, should I use a different one for every "Every x" and "Time =" events? What's the performance impact if that's not too much to ask?
B
6
S
2
Posts: 18
Reputation: 563

Post » Thu Mar 27, 2014 7:57 pm

nono, what i meant was that you
1) make a Global Variable called "timer" or wathever, which you set to 240
2) then you tell the system to subtract 1 every 1*st (60*dt = 1 second) while "timer" is greater than 0 (this event has 2 conditions)
3) and when "timer" is less or equal than 0; set the variable back to 240. so the timer loops. and also do what you want to do at this point. (I recommend that you add a "trigger once while true" to this event")

so, you don't really need to create any invisible objects for this, get used to the global variables. unless you need to have distinctive timers for different instances of the same object, in which case give the timer variable to the object instance variables.
then, if you need to display the "timer"'s value, you set the text to ("text"&timer) <--- the word "timer" refers to the variable "timer"
you could, in fact, make the variables inside the text object, but personally, i prefer to have variables like that in plain sight in the event sheet.


however... i'm sensing that you want the system to start spawning things after a certain amount of time has elapsed since the start of the layout? you can create a variable timer for that too =P
and in that case, use what i told you before, except don't restart that timer.
and in the following events you can use the "every x seconds" along with the "variable = 0" condition. So the every X seconds will only become active after the first variable is done. And it will reset every time you restart the layout.
B
43
S
12
G
6
Posts: 446
Reputation: 6,802

Next

Return to How do I....?

Who is online

Users browsing this forum: ChoosyZerk and 60 guests