Every X seconds independent for same objects

Get help using Construct 2

Post » Tue Nov 19, 2013 5:44 pm

Hi,

I can't work out how to do in events every x seconds to be different for each object of the same type depending on its variable value. So I have variable "Wait" and variable "Time" and I want every "Wait" to add 1 to "Time". Wait has got different value for each object. Please help!

Miko
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Nov 19, 2013 5:49 pm

I would suggest just using the timer behaviour. timer(name) <= 0, create timer (name, instance variable).

on timer(name): Add 1 to "time"

Effectively does what you're after with less room for trouble and more room for additions.
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Post » Tue Nov 19, 2013 5:52 pm

Thanks. I was looking for timer tutorials but cant find any. Would happen to know of one?

[email protected] to mention I need it to loop.megatronx2013-11-19 17:55:41
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Nov 19, 2013 6:07 pm

Hm, no sorry I kinda just learnt it myself. It's simple enough though, if you just read through the expressions.

Here's a picture which covers 2 different ways to get timers going on each of your units and how they trigger. If you have specific questions fire away :)

IMAGE

EDIT: Sorry, I still can't get images to post properly. Just follow the hyperlink.

EDIT 2: Both methods shown to start the timer loop. They just do it in different ways ('regular' setting automatically loops the timers, but the time comparison method creates a new timer every time the previous one expires).Tobye2013-11-19 18:12:25
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Post » Tue Nov 19, 2013 6:11 pm

Thanks.

got this, but it doesn't seam to work at all



[email protected] I've made a mistake, and left "Once", but changing to regular changed nothing. megatronx2013-11-19 18:13:14
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Nov 19, 2013 6:14 pm

First problem is that the timer is constantly being created, therefore never counting down ;) Add the condition that checks the timer is at or below 0 or make it an onCreated event with a regular timer.
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Post » Tue Nov 19, 2013 6:29 pm

Yeah, I've tried with trigger once while true. but the only one group starts. After moving things around first second group started moving but the movement seams broken. Does timer works per sprite?
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Nov 19, 2013 6:37 pm

No you don't want trigger once while true, just copy one of the methods in my image exactly as they are (except with your own timer and object names of course).

They both work perfectly for me. The 'on timer' works per sprite, but the creation doesn't, hence the need to use a for each loop or onCreated (which does occur for each one in case you weren't aware).

If you want, send a capx and I'll fix it for you.
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Post » Tue Nov 19, 2013 6:40 pm

Ok thanks. I'll give it a shot, and if im still stuck i will send the capx.

Ps. This drives me nuts for few days already ><''
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Tue Nov 19, 2013 6:48 pm

Yeah cool :) And I know your pain, I went through it just after timers were released and I was defiant to use them, for no reasonable reason. I created ways to do it, but all were harder without the added extras, so I strongly suggest you get comfortable with them to just make life that little bit easier.

Also something you might find relevant one day: every X seconds counts from start-up and not from start of layout. I once had two different layouts that ran scripted scenes and they both worked perfect alone. But when I tried to make one lead into the other, the timing was all messed up. I spent a damn long time trying to figure that one out! xD

EDIT: Actually I should add that timer behaviour is great for small things like this, but if you want a comprehensive timer system that allows pausing, dt adjustments and conditional count-downs etc., you still need a well evented system. I spent a long time refining separate, co-functioning timer systems for my RPG. The biggest hassle I came across was no way to reference the dt of an array, but that's a whole other story ^^

Another thing to remember is that the timer behaviour will count down using the dt of the instance using the behaviour. This can be a blessing or a curse, so remember it if you ever have the need to play with dt!Tobye2013-11-19 19:07:15
B
28
S
8
G
5
Posts: 429
Reputation: 7,007

Next

Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo, MaxxMunnn, mcscooter, Soluna Software and 26 guests