conditional wait minimum cooldown

Xbing

New Member
Reaction score
0
this is just a very basic general question, and although i have spent a little bit of effort searching for a thread on this topic, i only got 1 relevant thread with the keywords "minimum interval check condition", and though the thread does provide some possible answers, it does not totally answer my doubts.

i want to have a wait loop that waits for a condition to be true. it is now this:
Code:
          loop
                exitwhen ( Minigame_End_Check() )
                call TriggerSleepAction(2.00)
            endloop

it is not giving any problems yet as the interval between checking is 2 seconds. however, i noticed that in GUI world editor, the limit is 0.10 seconds, and it will not go below. even when it is converted to JASS whatever value entered will be compared to bj_WAIT_FOR_COND_MIN_INTERVAL which is 0.10 seconds and any value below will be ignored and the value of 0.10 will be used instead. *edit: Minigame_End_Check() is actually just a function that checks for a boolean that is going to be manually set to true when my "minigame" has ended.

so the question is:
if i want a more precise check (something like 0.01 seconds), i know it is a bad practice, will there be anything wrong(bugs etc.) with
Code:
          loop
                exitwhen ( Minigame_End_Check() )
                call TriggerSleepAction(0.01)
            endloop
i have tried testing this, it worked fine but i am doubtful of how clean it is, will it cause any internal errors or what?
 

Ayanami

칼리
Reaction score
288
Instead of using [ljass]TriggerSleepAction[/ljass], you could use a timer. A timer can go low as till 0 seconds interval.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
TSA's (Waits) are usually bad, timers are better.
But in any case, 0.01 is inaccurate in TSA's, they're almost always off IIRC.
 

Xbing

New Member
Reaction score
0
so timers are much more accurate than TSAs, and to apply it in this case i have to start a timer, then catch it with the exitwhen statement? so now i will need to check for 2 conditions, whether the timer is up, and whether the actual condition is true. Is that the implementation you have in mind?

thanks alot anyways.
 

Dirac

22710180
Reaction score
147
Hold on Xbing. The method you're using to "check if conditions are true" is the SAME as TSA, it's a BJ with a loop that cointains a TSA. You can add functions to timers when they end
JASS:
call TimerStart(timer,real wait,periodic boolean,function yourfunction)

example
JASS:
call TimerStart(MyTimer,10.,false,function endminigame)
 

tooltiperror

Super Moderator
Reaction score
231
TSA does not contain TSA in it, because TSA is not a BJ, it is a native, the good twin of BJs.
 

Dirac

22710180
Reaction score
147
What i meant is that he was using the Wait for condition action, isn't that a nasty BJ?
 

Sevion

The DIY Ninja
Reaction score
413
Why not something simple like this?

JASS:
function callback takes nothing returns nothing
    if ( theCondition == true ) then
        call endTheWait() // Or do it directly here
        call PauseTimer(GetExpiredTimer())
        call DestroyTimer(GetExpiredTimer())
    endif
endfunction

// Some other function
    call TimerStart(CreateTimer(), 0.0325, true, function callback)


I'm not so sure there's really truly any other way (that's not ugly and inefficient).

TSA would probably have to be used and that's no fun to use.
 

Bribe

vJass errors are legion
Reaction score
67
Rather than waiting until Minigame_End_Check is true,
there could very well be an event that you could spin
this off of. For example, if you're waiting until a unit
has life of 50%, there are events that can detect this
sort of thing.

You can really help us to help you if you tell us what
the Minigame_End_Check function is doing.
 

Xbing

New Member
Reaction score
0
i have updated the first post with what Minigame_End_Check does. i'm sorry, but i don't quite understand how to use the first timer example provided, as well as how TSAs are BJ or non BJ. however, for the second one, i understand that i am supposed to continue the rest of the function after the wait with the callback function, call another function to finish up the job with the rest of the job. if i am not mistaken, this would mean breaking up the function, and although there is no problem with the current triggers, just to ask, is there any way to have the conditional wait inside the function and continue inside? or will this be impossible if i want it to be clean. thanks.
 

Dirac

22710180
Reaction score
147
Minigame_End_Check() is actually just a function that checks for a boolean that is going to be manually set to true when my "minigame" has ended
If you're setting it manually then why are you waiting for it in another trigger? Instead of stetting something to true, place all your actions there. Some thing you should know
- Using TSAs is just plain wrong at wc3 programming.(there's always a better way to do it)
- TSAs are highly inaccurate (0.01 timeouts are actually 0.5 or something like that)
- There are lots of way to prevent using timers, such as event detection, in your case i don't know why you even created one :p
 

Xbing

New Member
Reaction score
0
If you're setting it manually then why are you waiting for it in another trigger? Instead of stetting something to true, place all your actions there. Some thing you should know
- Using TSAs is just plain wrong at wc3 programming.(there's always a better way to do it)
- TSAs are highly inaccurate (0.01 timeouts are actually 0.5 or something like that)
- There are lots of way to prevent using timers, such as event detection, in your case i don't know why you even created one :p

because there are many triggers setting the boolean, as there are many minigames. i wouldn't want to paste what is after the wait all over so many triggers. also, if i were to make a global function such as Actions_After_Minigame_End(), and run it after the minigames, it would be again, messy as the things the function belongs to the originial trigger. then again, it sounds quite neat too.

but i would still like to explore using the conditional wait ;)
 

Dirac

22710180
Reaction score
147
That's why there are PUBLIC functions, that way you don't have to put all the actions in every trigger
JASS:
public function EndMinigame takes nothing returns nothing
actions go here
endfunction

Just call this function every time you end your minigame
JASS:
call EndMinigame()


I insist, do NOT use TSAs if you wan't your map to be efficient
 

Xbing

New Member
Reaction score
0
yup, i did it the functions way. just wanted to explore if there were any efficient ways of using that conditional wait loop. seems like it is always inefficient, even with timers right?
 

Xbing

New Member
Reaction score
0
noted. and thanks! +rep

*edit: and, i just got a problem. apparently, the callback assigned to the timer does not support loops. calling a function normally through triggered events made the loop function normally, but when called from the timer, it simply runs just one time. is it an error on my side, or is it that the callback cannot contain loops.

*edit solved the problem. loops did work. ironically, it was a TSA in the callback function causing the trouble. just finished making my whole map use timers instead of TSAs.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top