Jump to content

two while statement running at the same time?


mianz
 Share

Recommended Posts

hi guys. i have this problem. i know it's a very common problem but i don't know how to search for it.

global $startstop

While 1

$nMsg = GUIGetMsg()

startbutton on click

-> call function

-> if $startstop = start then $startop = stop else $starstop = start

Wend

function abc()

while $startstop = "start"

blah blah

endfunc

ok, i know the computer is looping around function abc(), it is not detecting if startbutton is being click or not anymore. any tricks?

Link to comment
Share on other sites

You need to change place between "abc()" and "if $startstop etc" and use OnEventMode. If you don't get it to work then make a small runnable reproducer and post that so we can help you.

Edit: or do what bluelamp did :P

Edited by AdmiralAlkex
Link to comment
Share on other sites

Opt("GUIOnEventMode", 1)

GUICreate("t",400,400)
GUISetOnEvent(-3,"_EXIT")
GUIctrlSetOnEvent(GUICtrlCreateButton("Click",200,200,100),"_POLLING")

global $startstop = 0
GUISetState(@SW_SHOW)
While 1
    Sleep(1000)
    abc()
Wend

Func _EXIT()
    Exit
EndFunc
    
Func _POLLING()
    if $startstop == 1 Then
        $startstop = 0 
    else 
        $startstop = 1
    EndIf
EndFunc

func abc()
    $i=0
    while $startstop == 1
        ConsoleWrite($i&@CRLF)
        $i+=1
    WEnd
endfunc

This is an example how you could do it

Edited by bluelamp
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...