Jump to content
memerim

[Doubt] While + Call Function

Recommended Posts

HotkeySet("F2", "Example")

While 1

    $a = 1
    $b = 2
    $c = 3
    $d = 4
    $d = 5
    $e = 6   
    
Wend

Func Example()

    $x = 0
    
EndFunc

Suppose i press F2 while the loop are in line:

$c = 3

My doubt is, when the func ends the script returns to the begin of the loop ($a =1) or the line it was when i  pressed F2 ($c = 3)?

Share this post


Link to post
Share on other sites
Posted (edited)

1) the HotKeySet() help page is quite clear at this point.

2) while you're at it - what do you think should happen?

3) and what do you think should happen in a more complex scenario - like calling the hotkey inside a function? or inside a nested loop?

4) and why won't you check it yourself? run this and try. i won't provide any spoilers :-)

HotKeySet("{F2}", "Example")
Global $a
Global $bReport = False
Do
    $a = 1
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 2
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 3
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 4
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 5
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
    $a = 6
    If $bReport Then ConsoleWrite('$a=' & $a & @CRLF)
Until $bReport

Func Example()
    ConsoleWrite('hello, you pressed F2.' & @CRLF)
    $bReport = True
EndFunc   ;==>Example

 

Edited by orbs

Share this post


Link to post
Share on other sites

yes, it is possible, but before you do, you might want to review your logic.

if you want to do that anyways, then in the loop pick some key checkpoints to allow a safe ContinueLoop, and change the condition of the $bReport check to ContinueLoop instead of ConsoleWrite(). also change the loop condition to disregard $bReport, and instead, in the first line of the block of code inside the loop, you must re-initialize $bReport back to False.

also, naturally, rename $bReport to $bContinueLoop or such.

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...