Something I'd like to share about timer behaviour

Discussion and feedback on Construct 2

Post » Fri Apr 24, 2015 7:17 pm

blackhornet wrote:@megatronx
Maybe post a small example of what you are doing so people can have a look.


Not doing anything complicated. Basically have minions walking from base to the resources point, where timer is suppose to trigger their time working or offloading, and stop movement condition. On timer they suppose to get back to the base, one by one, each with own timer. When each one of them is at the base, the timer starts again stopping movement for short while, ( state is changed to Offload etc), and that's how they continue traveling back and forth. Units movement conditions where under For Each, Timer trigger was not, and at the end of mining or delivering conditions, timer was starting, on timer calling couple of functions responsible for setting targets. But after a while it would always drop one, or two, then three etc units, which would stand there with all the variables set to make a move, but doing nothing. And so I noticed that issue appear to happen at the time trigger moment. Removed it, replace with wait ( duplicated couple of actions unfortunately :/ ), and everything works as it supposed to.

Anyway, I don't even have original version of the events anymore I spent whole day trying to sort it out, moving things around. Nothing fixed the issue! I'll probably keep timer for simpler tasks from now on.

@newt If you have to use "for each" then that is a bug. No, when I placed a timer under For Each, it didn't work at all. Thought there was no error message either.

Possibly how the tags are set up. I sometimes set tags like this :< "name" & str(object.uid) > , but in both cases, weather it was just a name or name paired with uid, it didn't work, or rather, was bugy. It did display the tag properly in the debug, thought now I realised I didn't look up if tag's name uid is the same as the instance's.
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 » Fri Apr 24, 2015 7:24 pm

Yeah its does not work with concatenate or variables, and expressions I think.
You need just a plain string.
Image ImageImage
B
169
S
50
G
174
Posts: 8,330
Reputation: 110,804

Post » Fri Apr 24, 2015 7:40 pm

See if this helps.
blackhornettechnologies.com/Construct2Stuff/TimerExample20150424.capx
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Fri Apr 24, 2015 7:42 pm

sorry i haven't even read the first post.

anyway it's not bugged as much as i know, but it's 99% that you've made a mistake somewhere and it's hardly reachable / understandable where. that happens because we have events based engine which is sometimes hard to decrypt what happens.

anyway this could also happen if timers use threading. using many threads (each minion owning a thread) could cause issues if undelayin' performance is bad or optimization is not perfect. i've had my share of playin' with threading in c# where lots of stuff is perfectly declared what you can do and can't do, and trust me, it becomes a pain in the ass over some time to sync events.

using wait probably pauses that single picked instance and blocks that thread until time runs out and continues the thread then. using timer probably creates a new thread for counting down the time and stuff gets easily bugged. if wait works for you, then use it. if you really really really want to use timer, at least supply the part of code where we could see what happens and direct you into fixing stuff (or waste another day finding why it happens).

(it's the same as when i optimized 6 events shooting into 1 event (works like a charm :) ) )


also why would you use "timer.time - 1 sec" thing?

i'm a show you a part of my code how i set how often my enemies shoot. (Timers)
behold:
Image

oh yeah, difficulty - easy, medium and hard are described by 1,2,3.
so you get 1.2*(8/3*1) = ~ 3.2 sec for easy, ~2 sec for medium and 1.2 sec for hard.

oh yeah, i think i could have done this differently too - set a timer that is called every those sec, and call the upper function (swap places of on timer ) - but i think that would be slower. why? timer would fire it's part of code every time. and this way i check if fireing is disabled, if it is don't fire timer. else fire it.
;)
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Fri Apr 24, 2015 9:25 pm

So to conclude:

Setting timer within For Each loop doesn't work.

Timer trigger only works with strings, and doesn't work with changing variable, scaling functions and such.

Right?

@saiyadjin thanks, I'll use Wait for current events.
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 » Fri Apr 24, 2015 9:52 pm

Never used any variables inside Timers, never needed to so can't say much about that :/
For me it always work with integers and floats (1, 5, 23, 0.5 4.52 etc.... obviously xD) and expressions choose(), random() - at least these are the ones i usually use in Timers.

And For Each did not work with Timers on my last project (like I said few posts back).
ImageImageImageImage
B
157
S
66
G
42
Posts: 2,603
Reputation: 35,343

Post » Fri Apr 24, 2015 11:58 pm

Here is a capx that seems to do what Megatronx described in his post on top of that page.
No bug as far as I can tell, everything is working as intended.

And obviously, you can't "set a timer in a for each loop". "On timer" is a trigger. It will be the event triggered first. You can't run a "for each" loop every tick and have it recognize a trigger event inside it. That's not how events work, and it's not specific to the Timer behavior.

And no need to add a for each loop under it either, C2 does it internally (proof in my capx when you see the three workers you've created on the same tick moving away at the same time).

It all sounds as unproper events rather than actual bugs in C2 itself. Without a capx to look into though, no way to tell for sure.


Also if you try something like different tag names relying on the UID of the objects, it is just bad design on your part I'm afraid.
It obviously can't work, since, as mentioned, you would indeed need to loop through each instance to get its UID, and it can't work with the trigger system.
It's also, not required.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795

Post » Sat Apr 25, 2015 12:26 am

For each may be needed, depending on the circumstances.

viewtopic.php?f=152&t=122230&p=872914&hilit=for+each+timer#p872914
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sat Apr 25, 2015 1:00 am

Kyatric wrote:Here is a capx that seems to do what Megatronx described in his post on top of that page.
No bug as far as I can tell, everything is working as intended.

And obviously, you can't "set a timer in a for each loop". "On timer" is a trigger. It will be the event triggered first. You can't run a "for each" loop every tick and have it recognize a trigger event inside it. That's not how events work, and it's not specific to the Timer behavior.

And no need to add a for each loop under it either, C2 does it internally (proof in my capx when you see the three workers you've created on the same tick moving away at the same time).

It all sounds as unproper events rather than actual bugs in C2 itself. Without a capx to look into though, no way to tell for sure.


Also if you try something like different tag names relying on the UID of the objects, it is just bad design on your part I'm afraid.
It obviously can't work, since, as mentioned, you would indeed need to loop through each instance to get its UID, and it can't work with the trigger system.
It's also, not required.


Don't have beta installed, otherwise would check the capx.

Originally I had system like this:

For Each "Dude"
|State="A"
|| Distance between dude and his current target less/equal X
|| - Change State to "B"
|| - set Timer "Time" to Seconds
||Else
|| - Do Stuff, walk towards target etc

>On Timer "Time" : Call functions, Change Target, Set state to "A"

Everything else I did later on, all the changes, those were just an act of desperation. You all say this should work, and I also thought so, and it did for a bit, then started slowly dropping characters one by one.
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 » Sat Apr 25, 2015 1:14 am

megatronx wrote:You all say this should work, and I also thought so, and it did for a bit, then started slowly dropping characters one by one.


So it is fair to assume that you just messed up your code.
Since the examples of code that were provided in this topic do work as intended.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 15 guests