Jump to content

My script is not exiting the while loop. I need your help


 Share

Go to solution Solved by Ein,

Recommended Posts

I'm very new to scripting, despite giving my best shot I've now hit a wall and so i require your help.

Basically the gui only works sometimes and it seems like the script gets caught main() loop and doesn't exit when i call for stop() either via hotkey or GUI button

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\favicon.ico
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{F1}","main")
HotKeySet("{F2}","seconoption")
HotKeySet("{F9}","PixelRead")
HotKeySet("{F3}","stop")
HotKeySet("{F4}","_exit")

Global $Form1=GUICreate("Pixelreader test v0.1 By Ein",550,300)
Global $Pic=GUICtrlCreatePic(".\bin\GUI\ein.jpg",0,0,550,300)
Global $Group1=GUICtrlCreateGroup("",10,205,530,80)
Global $Button1=GUICtrlCreateButton("Start 1",25,220,145,55)
GUICtrlSetFont(-1, 18, 400, 0, "Impact")
Global $Button2=GUICtrlCreateButton("Start 2",200,220,145,55)
GUICtrlSetFont(-1, 18, 400, 0, "Impact")
Global $Button3=GUICtrlCreateButton("Stop",380,220,145,55)
GUICtrlSetFont(-1, 18, 400, 0, "Impact")
GUICtrlSetState($pic,$GUI_DISABLE)
GUISetState(@SW_SHOW)
dim $pos[2]
dim $color
Global $on=0

While 1
   Sleep(10)
    $msg = GUIGetMsg()
      Select
        Case $msg=$GUI_EVENT_CLOSE
            Exit
         Case $msg=$Button1
                        main()
         Case $msg=$Button2
            secondoption();I have yet to write this part of the code
         Case $msg=$Button3
            stop()
      EndSelect
   WEnd

Func stop()
   $on=0
EndFunc

Func PixelRead()
   $pos = MouseGetPos()
   $color = PixelGetColor($pos[0],$pos[1])
   IniWrite (".\bin\config.ini","Color","PxlColor",$color)
   MsgBox(0,"Set-up","You've selected " & @CRLF & $color)
EndFunc

Func  main()
   $on=1
   While $on=1
      Sleep(100)
      $pos=PixelSearch(100,100,1820,980,IniRead(".\bin\config.ini","Color","PxlColor",""),2)
      If Not @error Then
        ;Do stuff
      EndIf
   WEnd
EndFunc

Func _exit()
   MsgBox(0,"Quit","Exiting")
   Exit
EndFunc

I dont know what im doing wrong. any Help is greatly appreciated.

Link to comment
Share on other sites

See if this fixes your problem.

Just remove the MsgBox if you want, added it for testing.

Func  main()
    MsgBox(0, "test", "Start")
    If $on = 1 Then
        While $on=1
      Sleep(100)
      $pos=PixelSearch(100,100,1820,980,IniRead(".\bin\config.ini","Color","PxlColor",""),2)
      If Not @error Then
        ;Do stuff
      EndIf
   WEnd
    Else
        $on = 1
    EndIf
EndFunc

@ SirJohann,

If you run the script as it is and then click "Start" nothing will work after that. The While loop isn't allowing anything to get past it.

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

See if this fixes your problem.

Just remove the MsgBox if you want, added it for testing.

Func  main()
    MsgBox(0, "test", "Start")
    If $on = 1 Then
        While $on=1
      Sleep(100)
      $pos=PixelSearch(100,100,1820,980,IniRead(".\bin\config.ini","Color","PxlColor",""),2)
      If Not @error Then
        ;Do stuff
      EndIf
   WEnd
    Else
        $on = 1
    EndIf
EndFunc

@ SirJohann,

If you run the script as it is and then click "Start" nothing will work after that. The While loop isn't allowing anything to get past it.

 

I've no idea why but sometime it works some other times it just keeps looping on main(), maybe i need to do like a check at the beginning of the loop to check if button was pressed then Exitloop or something if i do any ideas how?

Edit: I've noticed that if i dont state that $on=1 at the beginning of the function the i have to click the start button twice before it actually does anythign

Edited by Ein
Link to comment
Share on other sites

I'm sorry, but with the fix I posted, does it still not work how you want it to?

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

I'm sorry, but with the fix I posted, does it still not work how you want it to?

 

Sadly it doesn't, the loop keeps me from calling any other functions (with your fix)

Edited by Ein
Link to comment
Share on other sites

Alright. Well, can you do a step-by-step explanation of what you want this to be doing?

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Basically what i want it to do is when start is pressed it will do the loop, and when i click the stop it will stop the loop. But the loop keeps running even after i hit the stop button or attempt to close the window, the only way to stop it is by Exit via right click on tray bar. I've been reading on how to interrupt a function but i have no idea how to apply that to my function, so i've been trying to see if i can do like a check to see if loop can loop before it does.

Im sorry if i can't explain it properly my knowledge on the matter and my poor english does not help.

Edit: the things i want it to do on the loop is to hold the mouse down at every pixel of the same color as the config.ini, that part works fine but the loop never ends its unstopable sort of XD

Edited by Ein
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...