Webcore piston problem

Hello, i swear webcore is driving me crazy, i’ve spent 4 hours already tried to do something fairly uncomplicated and i’ve debuged the piston and left now only the non working part of the code.
What i need the piston to do is simple, while a switch was turned on or off in the last 30 seconds, turn strobe ON on my siren every 5 secs, thats it


here are the logs

+1ms ╔Received event [Presence Marieta].switch = on with a delay of 33ms
+55ms ║RunTime Analysis CS > 15ms > PS > 27ms > PE > 14ms > CE
+58ms ║Runtime (36643 bytes) successfully initialized in 27ms (v0.3.110.20191009) (57ms)
+59ms ║╔Execution stage started
+162ms ║║Comparison (enum) on changed = false (96ms)
+164ms ║║Condition #10 evaluated false (100ms)
+165ms ║║Condition group #9 evaluated false (state did not change) (101ms)
+167ms ║╚Execution stage complete. (108ms)
+169ms ╚Event processed successfully (168ms)

why on earth it doesnt trigger my siren`s strobe.
Switch got turned on in the last 30 secs which means state DID change yet logs show that state did not changed hence not turning on my siren.
I really can’t understand why, i’ve done much more complicated pistons but this just blows my mind. I tried with/without task cancellation policy to default and always run.
If i change the piston to “if switch changes” it works but like that i can’t make the while loop to work only on the 1st 30 sec after switch was changed.

EDIT:
I managed to do this with a global bool variable that runs asynchronous and figure out if my switch was on for 30 secs based of the state of that variable but still i don’t understand why my 1st piston didin’t work.

The piston has fired because a switch event has been received. The status of the switch will have changed unless the developer has explicitly specified events will be propagated regardless.

You are querying if that switch changed state in the previous 30 seconds. The piston assumes that you don’t want to consider the event that just happened to cause the piston to run as if the value has changed you wouldn’t need to look back 30 seconds, and if it hasn’t it makes no difference.

so then how do i make the pistone consider the even that just happened ? any better way than my different approach withmy latter method with asynchronous global variables ?
again, i want a while loop to run as long as my switch has been turned on for no longer than 30 secs.

If you want the loop to run if the switch has been on in the last thirty seconds, that is the same as running the loop for thirty seconds when the switch has changed to on, or running it six times.

So you can start with ‘if switch changes to on’ (I notice you mentioned on, whereas your original piston just considered a change either way). Then you just need the loop.

Using while with a trigger (an event like switch changed) doesn’t make sense to me. Maybe try using ‘if’ instead of while. There is also a repeat statement in webcore that might handle the strobe.

Do you want the strobe to happen every time Marieta arrives AND every time she leaves?

it makes sense because the siren is a bad and unresponsive and i need to make sure it loops until it starts.
Is ok no worries, i managed to fix it using a variable that turns on and off in 30 secs and use the value of that variable for my while loop. Just thought it missed something and could have fixed my initial piston.
Basically the exact option is missing, i was looking for something like if the switch has changed and it’s been max 30 sec since it did so, then do something.
All good, thanks

If the switch changed in the last 30 seconds…

did you read the main post? that’s what i used and the piston isnt triggered .

I did…I would use an “If” block…Specifically, “If the switch changed in the last 30 seconds…”. From there, you can just repeat the action until the conditions and/or trigger/conditions are no longer evaluated as true.

using if switch changed in the last 30 secs is the same as while switch changed in the last 30 secs, it just doesn’t trigger when the switch changes

I beg to differ but seems like you got it figured out using a variable. Typically several different ways to approach logic in webCoRE and I’ve been using and testing the logic since beta. However, I would still use an “If” and not a “While” for your scenario.