Jump to content

Easy to fix error yet cant figure it out


Recommended Posts

im making this for myself to play with GUI functions, my problem is the ""Next keypress will be" section, it displays the most recent key pressed instead of the next one to be pressed

#include <GUIConstants.au3>
GUICreate("Bot Status",250,110,"","","",$WS_EX_STATICEDGE)
$font="Comic Sans MS"
GUISetFont(10,"","",$font)
GUISetState (@SW_SHOW)
GUICtrlCreateLabel("The Bot is Idle.                                       ","","")
WinSetOnTop("Bot Status","",1)
HotKeySet("{F1}", "moveon")

if not ProcessExists("wow.exe") Then GUICtrlCreateLabel("Please start wow.","","")
    
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

func moveon()
    GUICtrlCreateLabel("The Bot is Moving Around.","","")
    HotKeySet("{F1}", "rest")
        While 1
        
        $rand = Random(1,5,1) ; 1 = up, 2 = left, 3 = right, 4 = down, 5 = jump
        $timer = Random(30000,120000,1) ; 30 seconds to 2min

        GUICtrlCreateLabel("Next keypress will be:",1,+52)
        if $rand = 1 then
            GUICtrlCreateLabel("up.    ",147,+52)
        ElseIf $rand = 2 Then
            GUICtrlCreateLabel("left.    ",147, +52)
        ElseIf $rand = 3 then
            GUICtrlCreateLabel("right.    ",147,+52)
        Elseif $rand = 4 Then
            GUICtrlCreateLabel("down.    ",147,+52)
        ElseIf $rand = 5 Then
            GUICtrlCreateLabel("Space.    ",147,+52)
        EndIf
        
        if round($timer/1000) > 61 Then
            GUICtrlCreateLabel("Time until next action: 1min " & round($timer/1000-60,0) & " seconds. ",0,+30)
        ElseIf round($timer/1000) < 61 Then
            GUICtrlCreateLabel("Time until next action: " & round($timer/1000,0) & " seconds.      ",0,+30)
        EndIf
    
        
        if $rand = 1 Then
            Send("{up down}")
            sleep(200)
            Send("{up up}")
            Sleep($timer)
        Elseif $rand = 2 Then
            Send("{left down}")
            sleep(200)
            Send("{left up}")
            sleep($timer)
        ElseIf $rand = 3 Then
            Send("{Right down}")
            sleep(200)
            Send("{right up}")
            sleep($timer)
        ElseIf $rand = 4 then
            Send("{down down}")
            sleep(200)
            Send("{down up}")
            Sleep($timer)
        Elseif $rand = 5 Then
            Send("{space}")
            Sleep($timer)
        EndIf
    WEnd
EndFunc

func rest()
GUICtrlCreateLabel("The Bot is Idle.                                  ","","")
GUICtrlCreateLabel("                                                                   ",0,20)
GUICtrlCreateLabel("                                                                   ",0,52)

HotKeySet("{F1}", "moveon")

    while 1
        sleep(100)
    WEnd

EndFunc
Edited by Dead_Man
Link to comment
Share on other sites

You are just repeatedly creating labels. You need to assign all the GUI objects to handles and update them.

$GUIMain = GUICreate("Bot Status",250,110,"","","",$WS_EX_STATICEDGE)

.

.

.

$lblStatus = GUICtrlCreateLabel("The Bot is Moving Around.","","")

And then in the moveon, Use GuiCtrlSetData($lblStatus, "New Value") to update it to something else.

Link to comment
Share on other sites

You were updating the labels, then performing the action, then sleeping. You need to update the labels, THEN sleep, then perform the action. That way the labels are correct. I also changed your If's to Switches.. hope you don't mind, easier to read imo.

#include <GUIConstants.au3>
GUICreate("Bot Status",250,110,"","","",$WS_EX_STATICEDGE)
$font="Comic Sans MS"
GUISetFont(10,"","",$font)
GUISetState (@SW_SHOW)
GUICtrlCreateLabel("The Bot is Idle.                                       ","","")
WinSetOnTop("Bot Status","",1)
HotKeySet("{F1}", "moveon")

if not ProcessExists("wow.exe") Then GUICtrlCreateLabel("Please start wow.","","")
   
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

func moveon()
    Local $hLabel
    Local $bFirstRun = True
    
    GUICtrlCreateLabel("The Bot is Moving Around.","","")
    GUICtrlCreateLabel("Next keypress will be:",1,+52)
    $hLabelUpdate = GUICtrlCreateLabel("",0,30,250)
    $hLabelKey = GUICtrlCreateLabel("up",147,52,50)
    
    HotKeySet("{F1}", "rest")
        While 1
       
        $rand = Random(1,5,1) ; 1 = up, 2 = left, 3 = right, 4 = down, 5 = jump
        $timer = Random(30000,120000,1) ; 30 seconds to 2min

        ; First run, we'll skip setting all the labels, and do an action right away. 
        If Not $bFirstRun Then
            ConsoleWrite("ok")
            Switch $rand
                Case 1
                    GuiCtrlSetData($hLabelKey,"up")
                Case 2
                    GuiCtrlSetData($hLabelKey,"left")
                Case 3
                    GuiCtrlSetData($hLabelKey,"right")
                Case 4
                    GUICtrlSetData($hLabelKey, "down")
                Case 5
                    GUICtrlSetData($hLabelKey, "Space")
            EndSwitch
               
            if round($timer/1000) > 61 Then
                GUICtrlSetData($hLabelUpdate, "Time until next action: 1min " & round($timer/1000-60,0) & " seconds. ")
            ElseIf round($timer/1000) < 61 Then
                GUICtrlSetData($hLabelUpdate, "Time until next action: " & round($timer/1000,0) & " seconds.      ")
            EndIf
        
            Sleep($timer) ; Now we sleep, before the action is actually performed. 
        EndIf


        Switch $rand
            Case 1
                Send("{up down}")
                sleep(200)
                Send("{up up}")
            Case 2
                Send("{left down}")
                sleep(200)
                Send("{left up}")
            Case 3
                Send("{Right down}")
                sleep(200)
                Send("{right up}")
            Case 4
                Send("{down down}")
                sleep(200)
                Send("{down up}")
            Case 5
                Send("{space}")
        EndSwitch
        
        $bFirstRun = False
    WEnd
EndFunc

func rest()
GUICtrlCreateLabel("The Bot is Idle.                                  ","","")
GUICtrlCreateLabel("                                                                   ",0,20)
GUICtrlCreateLabel("                                                                   ",0,52)

HotKeySet("{F1}", "moveon")

    while 1
        sleep(100)
    WEnd

EndFunc
Link to comment
Share on other sites

You were updating the labels, then performing the action, then sleeping. You need to update the labels, THEN sleep, then perform the action. That way the labels are correct. I also changed your If's to Switches.. hope you don't mind, easier to read imo.

thanks a lot and i don't mind at all, i never learned switches and thats why i didn't do them, guess its time to learn

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...