Programm hängt bei starten einer Funktion...

  • Abend beisammen,

    also ich Code seit heute Nachmittag Autoit und programmiere momentan einen Silkroad Online Autopotter. Wenn ich jedoch auf den Startknopf drücke hängt das Programm und lässt sich nur noch über den Taskmanager beenden.
    Eventuell weiß auch einer wie ich den Pauseknopf programmieren kann sodass er wirklich stoppt wenn ich darauf klicke.

    Hoffe ihr blickt durch meinen Code:

    Spoiler anzeigen
    [autoit]

    ; SRO Autopotter 0.8
    ; Author: born2die
    ; Copyright 2008 152x87, 152x93 rgb=DA4348 rgb=F7DA4E

    [/autoit] [autoit][/autoit] [autoit]

    #include
    Global $health = "1"
    Global $food = "2"
    Global $sro_name

    [/autoit] [autoit][/autoit] [autoit]

    $Sro = GUICreate("Sro Autopotter by born2die 0.8", 285, 340, 193, 125)
    $Group1 = GUICtrlCreateGroup("Autopot", 24, 8, 65, 89)
    $Checkbox1 = GUICtrlCreateCheckbox("Life", 32, 32, 57, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $Checkbox2 = GUICtrlCreateCheckbox("Food", 32, 56, 49, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Start", 104, 16, 73, 25, 0)
    $Button2 = GUICtrlCreateButton("Stop", 104, 48, 75, 25, 0)
    $Button3 = GUICtrlCreateButton("About", 192, 16, 75, 25, 0)
    $Button4 = GUICtrlCreateButton("Exit", 192, 48, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Copyright by born2die 2008", 24, 312, 133, 17)
    $Group2 = GUICtrlCreateGroup("Place of Life", 24, 112, 185, 89)
    $Radio1 = GUICtrlCreateRadio("1", 72, 144, 25, 17)
    $Radio2 = GUICtrlCreateRadio("2", 104, 144, 25, 17)
    $Radio3 = GUICtrlCreateRadio("3", 136, 144, 33, 17)
    $Radio4 = GUICtrlCreateRadio("4", 168, 144, 25, 17)
    $Radio5 = GUICtrlCreateRadio("5", 32, 168, 25, 17)
    $Radio6 = GUICtrlCreateRadio("6", 72, 168, 25, 17)
    $Radio7 = GUICtrlCreateRadio("7", 104, 168, 25, 17)
    $Radio8 = GUICtrlCreateRadio("8", 136, 168, 25, 17)
    $Radio9 = GUICtrlCreateRadio("9", 168, 168, 25, 17)
    $Radio10 = GUICtrlCreateRadio("0", 32, 144, 25, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group3 = GUICtrlCreateGroup("Place of Food", 22, 215, 185, 89)
    $Radio11 = GUICtrlCreateRadio("1", 70, 247, 25, 17)
    $Radio12 = GUICtrlCreateRadio("2", 102, 247, 25, 17)
    $Radio13 = GUICtrlCreateRadio("3", 134, 247, 33, 17)
    $Radio14 = GUICtrlCreateRadio("4", 166, 247, 25, 17)
    $Radio15 = GUICtrlCreateRadio("5", 30, 271, 25, 17)
    $Radio16 = GUICtrlCreateRadio("6", 70, 271, 25, 17)
    $Radio17 = GUICtrlCreateRadio("7", 102, 271, 25, 17)
    $Radio18 = GUICtrlCreateRadio("8", 134, 271, 25, 17)
    $Radio19 = GUICtrlCreateRadio("9", 166, 271, 25, 17)
    $Radio20 = GUICtrlCreateRadio("0", 30, 247, 25, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Input1 = GUICtrlCreateInput("Silkroad-Online", 152, 88, 121, 21)
    $Label2 = GUICtrlCreateLabel("Sro-Name:", 96, 88, 54, 17)
    $Label3 = GUICtrlCreateLabel("Sleeptime:", 216, 120, 53, 17)
    $Input2 = GUICtrlCreateInput("3", 216, 144, 57, 21)
    Opt("TrayIconHide", 1)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    pot()
    Case $Button2
    Case $Button3
    MsgBox(0, "Sro Autopotter", "Sro Autopotter made by born2die" & @CR & "Version 0.8" & @CR & "Copyright 2008")
    Case $Button4
    Exit
    EndSwitch
    WEnd
    Func pot()
    $sro_name = GUICtrlGetState($Input1)
    GetHealth()
    GetFood()
    if $health == $food Then
    MsgBox(16, "Error!", "Health and Food have the same Number, that doesn't work!")
    Exit
    EndIf
    $sleep = GUICtrlGetState($Input2) * 1000
    While 1
    If WinWaitActive($sro_name) Then
    If (GUICtrlGetState($Checkbox1) == $GUI_CHECKED) Then
    If PixelGetColor(152, 87) <> 0xDA4348 Then Send($health) ;prüfen ob das Leben unter ca 50% ist
    EndIf
    If (GUICtrlGetState($Checkbox2) == $GUI_CHECKED) Then
    If PixelGetColor(152, 93) <> 0xF7DA4E Then Send($food) ;prüfen ob Hunger unter ca 50% ist
    EndIf
    EndIf
    Sleep($sleep)
    WEnd
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func GetHealth()
    If GUICtrlGetState($Radio1) == $GUI_CHECKED Then $health = 1
    If GUICtrlGetState($Radio2) == $GUI_CHECKED Then $health = 2
    If GUICtrlGetState($Radio3) == $GUI_CHECKED Then $health = 3
    If GUICtrlGetState($Radio4) == $GUI_CHECKED Then $health = 4
    If GUICtrlGetState($Radio5) == $GUI_CHECKED Then $health = 5
    If GUICtrlGetState($Radio6) == $GUI_CHECKED Then $health = 6
    If GUICtrlGetState($Radio7) == $GUI_CHECKED Then $health = 7
    If GUICtrlGetState($Radio8) == $GUI_CHECKED Then $health = 8
    If GUICtrlGetState($Radio9) == $GUI_CHECKED Then $health = 9
    If GUICtrlGetState($Radio10) == $GUI_CHECKED Then $health = 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func GetFood()
    If GUICtrlGetState($Radio11) == $GUI_CHECKED Then $health = 1
    If GUICtrlGetState($Radio12) == $GUI_CHECKED Then $health = 2
    If GUICtrlGetState($Radio13) == $GUI_CHECKED Then $health = 3
    If GUICtrlGetState($Radio14) == $GUI_CHECKED Then $health = 4
    If GUICtrlGetState($Radio15) == $GUI_CHECKED Then $health = 5
    If GUICtrlGetState($Radio16) == $GUI_CHECKED Then $health = 6
    If GUICtrlGetState($Radio17) == $GUI_CHECKED Then $health = 7
    If GUICtrlGetState($Radio18) == $GUI_CHECKED Then $health = 8
    If GUICtrlGetState($Radio19) == $GUI_CHECKED Then $health = 9
    If GUICtrlGetState($Radio20) == $GUI_CHECKED Then $health = 0
    EndFunc

    [/autoit]


    Danke Schonmal
    mfg
    born2die
    </GUIConstants.au3>

    • Offizieller Beitrag

    Hi,

    wie kommt er denn hier wieder raus?

    [autoit]

    $sleep = GUICtrlGetState($Input2) * 1000
    While 1
    If WinWaitActive($sro_name) Then
    If (GUICtrlGetState($Checkbox1) == $GUI_CHECKED) Then
    If PixelGetColor(152, 87) <> 0xDA4348 Then Send($health) ;prüfen ob das Leben unter ca 50% ist
    EndIf
    If (GUICtrlGetState($Checkbox2) == $GUI_CHECKED) Then
    If PixelGetColor(152, 93) <> 0xF7DA4E Then Send($food) ;prüfen ob Hunger unter ca 50% ist
    EndIf
    EndIf
    Sleep($sleep)
    WEnd

    [/autoit]

    und außerdem heißt GUICtrlRead von den Inhalt des INPUTs auslesen willst.

    Mega

  • Ich habe mal ein bissel gebastelt und würde es vielleicht nicht ganz so lösen wie du (vom Aufbau her) wenn du auf Events reagierst dürfte es besser klappen.

    Spoiler anzeigen
    [autoit]

    ; SRO Autopotter 0.8
    ; Author: born2die
    ; Copyright 2008 152x87, 152x93 rgb=DA4348 rgb=F7DA4E

    [/autoit] [autoit][/autoit] [autoit]

    #include <GUIConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode",1)
    Opt("TrayIconHide", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $health = "1"
    Global $food = "2"
    Global $sro_name

    [/autoit] [autoit][/autoit] [autoit]

    $Sro = GUICreate("Sro Autopotter by born2die 0.8", 285, 340, 193, 125)
    $Group1 = GUICtrlCreateGroup("Autopot", 24, 8, 65, 89)
    $Checkbox1 = GUICtrlCreateCheckbox("Life", 32, 32, 57, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $Checkbox2 = GUICtrlCreateCheckbox("Food", 32, 56, 49, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("Start", 104, 16, 73, 25, 0)
    $Button2 = GUICtrlCreateButton("Stop", 104, 48, 75, 25, 0)
    $Button3 = GUICtrlCreateButton("About", 192, 16, 75, 25, 0)
    $Button4 = GUICtrlCreateButton("Exit", 192, 48, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Copyright by born2die 2008", 24, 312, 133, 17)
    $Group2 = GUICtrlCreateGroup("Place of Life", 24, 112, 185, 89)
    $Radio1 = GUICtrlCreateRadio("1", 72, 144, 25, 17)
    $Radio2 = GUICtrlCreateRadio("2", 104, 144, 25, 17)
    $Radio3 = GUICtrlCreateRadio("3", 136, 144, 33, 17)
    $Radio4 = GUICtrlCreateRadio("4", 168, 144, 25, 17)
    $Radio5 = GUICtrlCreateRadio("5", 32, 168, 25, 17)
    $Radio6 = GUICtrlCreateRadio("6", 72, 168, 25, 17)
    $Radio7 = GUICtrlCreateRadio("7", 104, 168, 25, 17)
    $Radio8 = GUICtrlCreateRadio("8", 136, 168, 25, 17)
    $Radio9 = GUICtrlCreateRadio("9", 168, 168, 25, 17)
    $Radio10 = GUICtrlCreateRadio("0", 32, 144, 25, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group3 = GUICtrlCreateGroup("Place of Food", 22, 215, 185, 89)
    $Radio11 = GUICtrlCreateRadio("1", 70, 247, 25, 17)
    $Radio12 = GUICtrlCreateRadio("2", 102, 247, 25, 17)
    $Radio13 = GUICtrlCreateRadio("3", 134, 247, 33, 17)
    $Radio14 = GUICtrlCreateRadio("4", 166, 247, 25, 17)
    $Radio15 = GUICtrlCreateRadio("5", 30, 271, 25, 17)
    $Radio16 = GUICtrlCreateRadio("6", 70, 271, 25, 17)
    $Radio17 = GUICtrlCreateRadio("7", 102, 271, 25, 17)
    $Radio18 = GUICtrlCreateRadio("8", 134, 271, 25, 17)
    $Radio19 = GUICtrlCreateRadio("9", 166, 271, 25, 17)
    $Radio20 = GUICtrlCreateRadio("0", 30, 247, 25, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Input1 = GUICtrlCreateInput("Silkroad-Online", 152, 88, 121, 21)
    $Label2 = GUICtrlCreateLabel("Sro-Name:", 96, 88, 54, 17)
    $Label3 = GUICtrlCreateLabel("Sleeptime:", 216, 120, 53, 17)
    $Input2 = GUICtrlCreateInput("3", 216, 144, 57, 21)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetOnEvent($Button1, "_start")
    GUICtrlSetOnEvent($Button2, "_stop")
    GUICtrlSetOnEvent($Button3, "_info")
    GUICtrlSetOnEvent($Button4, "_exit")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(1000)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _start()
    $sro_name = GUICtrlGetState($Input1)
    GetHealth()
    GetFood()
    if $health == $food Then
    MsgBox(16, "Error!", "Health and Food have the same Number, that doesn't work!")
    Exit
    EndIf
    AdlibEnable("pot",GUICtrlRead($Input2) * 1000)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _stop()
    AdlibDisable()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _info()
    MsgBox(0, "Sro Autopotter", "Sro Autopotter made by born2die" & @CR & "Version 0.8" & @CR & "Copyright 2008")
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func pot()
    If WinWaitActive($sro_name) Then
    If (GUICtrlGetState($Checkbox1) == $GUI_CHECKED) Then
    If PixelGetColor(152, 87) <> 0xDA4348 Then Send($health) ;prüfen ob das Leben unter ca 50% ist
    EndIf
    If (GUICtrlGetState($Checkbox2) == $GUI_CHECKED) Then
    If PixelGetColor(152, 93) <> 0xF7DA4E Then Send($food) ;prüfen ob Hunger unter ca 50% ist
    EndIf
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func GetHealth()
    If GUICtrlGetState($Radio1) == $GUI_CHECKED Then $health = 1
    If GUICtrlGetState($Radio2) == $GUI_CHECKED Then $health = 2
    If GUICtrlGetState($Radio3) == $GUI_CHECKED Then $health = 3
    If GUICtrlGetState($Radio4) == $GUI_CHECKED Then $health = 4
    If GUICtrlGetState($Radio5) == $GUI_CHECKED Then $health = 5
    If GUICtrlGetState($Radio6) == $GUI_CHECKED Then $health = 6
    If GUICtrlGetState($Radio7) == $GUI_CHECKED Then $health = 7
    If GUICtrlGetState($Radio8) == $GUI_CHECKED Then $health = 8
    If GUICtrlGetState($Radio9) == $GUI_CHECKED Then $health = 9
    If GUICtrlGetState($Radio10) == $GUI_CHECKED Then $health = 0
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func GetFood()
    If GUICtrlGetState($Radio11) == $GUI_CHECKED Then $health = 1
    If GUICtrlGetState($Radio12) == $GUI_CHECKED Then $health = 2
    If GUICtrlGetState($Radio13) == $GUI_CHECKED Then $health = 3
    If GUICtrlGetState($Radio14) == $GUI_CHECKED Then $health = 4
    If GUICtrlGetState($Radio15) == $GUI_CHECKED Then $health = 5
    If GUICtrlGetState($Radio16) == $GUI_CHECKED Then $health = 6
    If GUICtrlGetState($Radio17) == $GUI_CHECKED Then $health = 7
    If GUICtrlGetState($Radio18) == $GUI_CHECKED Then $health = 8
    If GUICtrlGetState($Radio19) == $GUI_CHECKED Then $health = 9
    If GUICtrlGetState($Radio20) == $GUI_CHECKED Then $health = 0
    EndFunc

    [/autoit]

    Mfg
    Jens (McPoldy)

    Twitter: jkroeger

    Denn die Dinge, die wir erst lernen müssen, bevor wir sie tun, lernen wir beim Tun.(Aristoteles)

  • @Xeno soll ich das per Variable machen? also while $var == true zb?
    thx

    McPoldy den Source kann ich momentan net anschauen hol ich aber nach!
    Hab grad kA was du mit Events meinst bzw find nix dazu...

  • Moin, vielleicht zur Erklärung was ich in meinem Quelltext gemacht habe bzw. was OnEvent heißt.

    In Deinem Skript hast du eine GUI die aufgerufen wird und anschliessend eine While Schleife die immer wieder abfragt ob der Benutzer einen Knopf/Button gedrückt hat. Drückt nun jemand Start, springst Du in die Funktion pot(), das heißt das die GUI Ereignisse nicht mehr abgefragt werden, wenn also z. B. jemand auf Stop klickt. Wenn du nun Opt("GUIOnEventMode",1) (In der Hilfe unterAutoIt -> GUI Reference -> GUI OnEventModus) setzt, wird eine Function aufgerufen wenn du auf einen Knopf drückst. Das zweite was ich anders gemacht habe, ich habe Adlib genutzt, so wird deine put() Funktion je nach Zeitangabe aufgerufen, es können aber auch noch andere Buttons genutzt werden ( du hast oben gefragt wie man es hin bekommt das man die Stop Taste drückt und auch was passiert).

    Mfg
    Jens (McPoldy)

    Twitter: jkroeger

    Denn die Dinge, die wir erst lernen müssen, bevor wir sie tun, lernen wir beim Tun.(Aristoteles)