Jump to content
Sign in to follow this  
Zerohour

New coder entirly needs help!

Recommended Posts

Zerohour

Well I've been working my ass off trying to figure out how to do this and I think I've figured it out except I keep getting an error about WEnd. I'm completly lost and out of my league.

; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will open an input box where you can start or stop a script to feed your mag in PSO:BB. Run?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(4096, "AutoIt", "OK.  Bye!")
    Exit
EndIf

    $text = InputBox("AutoIt Example", "Please type in the word ""start"" to initialize or ""stop"" to halt and close the sctipt.")
    If @error = 1 Then
        MsgBox(4096, "Error", "You pressed 'Cancel' - Closing!")
        EndIf
        If $text = "start" Then
            MsgBox(4096, "Initalizing", "Starting the script - Here we go!")
            WinActivate ("PHANTASY STAR ONLINE Blue Burst")
            $bLoop = 1
            $cnt = 0
            While $bLoop = 1
            sleep( (1000 * 60) )
            $cnt = $cnt + 1
            if $cnt = 5 then
            Send("{ESC 3}")
            Sleep(500)
            Send("{F4}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ESC 5}")
            EndIf
            If $cnt = 16 then
            Send("{ESC 3}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{DOWN 3}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{DOWN}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ESC 3}")
            if $cnt > 17 then
            $cnt = 0; Reseting Timer            
        EndIf
        If $text = "stop" Then
            MsgBox(4096, "Halting", "Stoping the script - Goodbye!")
            $bLoop = 0   ; Exit the loop - ExitLoop would have been an alternative too :)
        EndIf

; Print the success message
MsgBox(4096,"AutoIt Example", "Script Stoped.")

; Finished

The error is:

Line 81

; Finished

Error: "While" statement has no matching "WEnd" statement.

Any help would be apreciated!

Share this post


Link to post
Share on other sites
Sokko

The error message speaks the truth. Your "While $bLoop = 1" statement has no matching "WEnd", which marks the point at which the code to be looped stops. Like:

While $variable = 123
    ;Code to be looped as long as $variable equals 123
WEnd
Edited by Sokko

Share this post


Link to post
Share on other sites
BigDod

; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will open an input box where you can start or stop a script to feed your mag in PSO:BB. Run?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(4096, "AutoIt", "OK.  Bye!")
    Exit
EndIf

    $text = InputBox("AutoIt Example", "Please type in the word ""start"" to initialize or ""stop"" to halt and close the sctipt.")
    If @error = 1 Then
        MsgBox(4096, "Error", "You pressed 'Cancel' - Closing!")
        EndIf
        If $text = "start" Then
            MsgBox(4096, "Initalizing", "Starting the script - Here we go!")
            WinActivate ("PHANTASY STAR ONLINE Blue Burst")
            $bLoop = 1
            $cnt = 0
[COLOR=red]EndIf[/COLOR]
            While $bLoop = 1
            sleep( (1000 * 60) )
[COLOR=red]WEnd[/COLOR]
            $cnt = $cnt + 1
            if $cnt = 5 then
            Send("{ESC 3}")
            Sleep(500)
            Send("{F4}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ESC 5}")
            EndIf
            If $cnt = 16 then
            Send("{ESC 3}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{DOWN 3}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{DOWN}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ESC 3}")
[COLOR=red]EndIf[/COLOR]
            if $cnt > 17 then
            $cnt = 0; Reseting Timer            
        EndIf
        If $text = "stop" Then
            MsgBox(4096, "Halting", "Stoping the script - Goodbye!")
            $bLoop = 0  ; Exit the loop - ExitLoop would have been an alternative too :)
        EndIf

; Print the success message
MsgBox(4096,"AutoIt Example", "Script Stoped.")

; Finished

I have marked in red the ones that I have noticed :whistle::dance::dance:

EDIT

Oops the colouring did not work !!!

Edited by BigDod


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
Zerohour

Thanks for the speedy replies. Since this was my first time coding ever, I don't think I did too bad! :whistle:

Share this post


Link to post
Share on other sites
SmOke_N

Err you can only color code in quotes... :whistle:

Edit:

Change [ code ] [ / code ]

To [ quote ] [ / quote ]

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Zerohour

That fixed the errors when I tried to start the script but the input box didn't stay open for me to actually type in stop to turn it off. :dance:

Any sugestions on how to do this?

(I know you can turn the script off in the taskbar but I wanted to do a complex setup for my first try so that I could learn more than just send! :whistle:)

BTW: I was wondering if I could have it setup to select the window each counter period that way I can still do other stuff on my computer. Would that be possible without interupting the script?

Edited by Zerohour

Share this post


Link to post
Share on other sites
SmOke_N

You would need a GUI to stay up if you wanted to use "Stop and Start".

What exactly would you like to do... and maybe we could give an idea on how we would attempt it.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Zerohour

I was attempting to make my script into a trashy app :whistle:

What I want it do is to have the input box continue to run while the script is going, that way you can turn it off and on without completly disabling it.

i.e. You typed start into the box and the script start! Wooo! but you need to stop it and you want to be lazy so you just type stop into the box. Viola, the script is stoped and you can easily start it up again.

Maby a better solution would to be a "pause" feature.

Is that even possible with autoit?

Also, could someone please answer this?

BTW: I was wondering if I could have it setup to select the window each counter period that way I can still do other stuff on my computer. Would that be possible without interupting the script?

Edited by Zerohour

Share this post


Link to post
Share on other sites
SmOke_N

The pause button would be a HotKey.... (nicely demonstrated in the helpfile)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Valuater

heres a small idea... i think it looks cleaner

; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will open an input box where you can start or stop a script to feed your mag in PSO:BB.  " & @CRLF & @CRLF & "   Please press yes to  *Run*  the program  ")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(4096, "AutoIt", "OK.  Bye!", 1.5)
    Exit
EndIf

the original message has two lines and the "good bye" message box leaves after 1.5 seconds

you should use this same timer idea on the other " good bye" message boxes

hope that helps

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Zerohour

Hmmm, I guess it was overkill to have "start" and "stop" in there than.

I'll dig around the help file and see what I can pull up on the "hotkey". Everything that's part of the script I've stolen from the example files. Just the way I learn I guess.

Any suggestions on how I should remove the input box then?

heres a small idea... i think it looks cleaner

; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will open an input box where you can start or stop a script to feed your mag in PSO:BB.  " & @CRLF & @CRLF & "   Please press yes to  *Run*  the program  ")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(4096, "AutoIt", "OK.  Bye!", 1.5)
    Exit
EndIf

the original message has two lines and the "good bye" message box leaves after 1.5 seconds

you should use this same timer idea on the other " good bye" message boxes

hope that helps

8)

<{POST_SNAPBACK}>

I'll look into it. I think I'm the only person who's going to use it so I don't really care. :whistle: Edited by Zerohour

Share this post


Link to post
Share on other sites
Zerohour

Going into the help file I found the script for pausing but I'm curious.

Global $Paused

HotKeySet("{PAUSE}", "TogglePause")

is obvious enough but,

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(100)

ToolTip('Script is "Paused"',0,0)

WEnd

ToolTip("")

EndFunc

Wouldn't that mean that the script would only be paused for .1 sec?

Not to mention I'm still not exactly sure how I should cutout the input box either. :whistle:

Edited by Zerohour

Share this post


Link to post
Share on other sites
SmOke_N

#include <GUICONSTANTS.AU3>
Opt("WINTITLEMATCHMODE", 4)

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")

$MAIN_GUI = GUICreate("AutoIt Example", 125, 50)
$BUTTON_1 = GUICtrlCreateButton("START", 10, 10, 50, 30, $BS_DEFPUSHBUTTON)
$BUTTON_2 = GUICtrlCreateButton("STOP", 65, 10, 50, 30, $BS_DEFPUSHBUTTON)

GUISetState()


While 1
   $MSG = GUIGetMsg()
   Select
      Case $MSG = $GUI_EVENT_CLOSE
         Exit
      Case $MSG = $BUTTON_1
         MAIN_LOOP()
      Case $MSG = $BUTTON_2
         If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
         $iMsgBoxAnswer = MsgBox(4,"Exit Chose","Are you sure you want to Exit?")
         Select
            Case $iMsgBoxAnswer = 6
               Exit
         EndSelect
   EndSelect
WEnd

Func MAIN_LOOP()
   $CNT = 0
   While 1
      Sleep(60000)
      $CNT = $CNT + 1
      If Not WinActive("PHANTASY STAR ONLINE Blue Burst") Then WinActivate("PHANTASY STAR ONLINE Blue Burst")
      If $CNT = 5 Then
         Send("{ESC 3}")
         Sleep(500)
         Send("{F4}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(3000)
         Send("{ENTER}")
         Sleep(3000)
         Send("{ENTER}")
         Sleep(3000)
         Send("{ESC 5}")
      EndIf
      If $CNT = 16 Then
         If Not WinActive("PHANTASY STAR ONLINE Blue Burst") Then WinActivate("PHANTASY STAR ONLINE Blue Burst")
         Send("{ESC 3}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(500)
         Send("{DOWN 3}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(500)
         Send("{DOWN}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(500)
         Send("{ENTER}")
         Sleep(500)
         Send("{ESC 3}")
         $CNT = 0
      EndIf
   WEnd
EndFunc ;==>MAIN_LOOP

Func TogglePause()
   $Paused = NOT $Paused
   While $Paused
      sleep(100)
      ToolTip('Script is "Paused"',0,0)
   WEnd
   ToolTip("")
EndFunc ;==>TogglePause

You can add whatever you want to it...

EDIT: Forgot to add something for $Button_2 (Stop)

EDIT_2: Had counter in the wrong place.

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
quick_sliver007

Going into the help file I found the script for pausing but I'm curious.

Global $Paused

HotKeySet("{PAUSE}", "TogglePause")

is obvious enough but,

Func TogglePause()

$Paused = NOT $Paused

While $Paused

  sleep(100)

  ToolTip('Script is "Paused"',0,0)

WEnd

ToolTip("")

EndFunc

Wouldn't that mean that the script would only be paused for .1 sec?

Not to mention I'm still not exactly sure how I should cutout the input box either.  :whistle:

<{POST_SNAPBACK}>

Think of While $paused as While 1. Also think of $paused = NOT $paused as...
If $paused = 0 then
   $paused = 1
Else
   $paused = 0
EndIf

So if $paused = 1 then the loop runs until $paused = 0.

Also think of 1 as true and 0 as false. So it is like if $paused = true then do loop, if pause = false then don't do loop.


.

Share this post


Link to post
Share on other sites
Zerohour

I'm a bit confused on how you set up the counter. Why'd you put it at the end? I had set the counter up so that every minute it added 1. With the counter set up like that would it still work the same?

The code winds up looking like this when I edited it using how you set it up. Please correct me if this is wrong.

#include <GUICONSTANTS.AU3>
Opt("WINTITLEMATCHMODE", 4)

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")

$MAIN_GUI = GUICreate("AutoIt Example", 125, 50)
$BUTTON_1 = GUICtrlCreateButton("START", 10, 10, 50, 30, $BS_DEFPUSHBUTTON)
$BUTTON_2 = GUICtrlCreateButton("STOP", 65, 10, 50, 30, $BS_DEFPUSHBUTTON)

GUISetState()


While 1
   $MSG = GUIGetMsg()
   Select
      Case $MSG = $GUI_EVENT_CLOSE
         Exit
      Case $MSG = $BUTTON_1
         MAIN_LOOP()
      Case $MSG = $BUTTON_2
         If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
         $iMsgBoxAnswer = MsgBox(4,"Exit Chose","Are you sure you want to Exit?")
         Select
            Case $iMsgBoxAnswer = 6
               Exit
         EndSelect
   EndSelect
WEnd

Func MAIN_LOOP()
   $CNT = 0
   While 1
      Sleep(60000)
      $CNT = $CNT + 1
        If $CNT = 5 Then
        If Not WinActive("PHANTASY STAR ONLINE Blue Burst") Then WinActivate("PHANTASY STAR ONLINE Blue Burst")
            Send("{ESC 3}")
            Sleep(500)
            Send("{F4}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ESC 5}")
        EndIf
        If $CNT = 10 Then
        If Not WinActive("PHANTASY STAR ONLINE Blue Burst") Then WinActivate("PHANTASY STAR ONLINE Blue Burst")
            Send("{ESC 3}")
            Sleep(500)
            Send("{F4}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ESC 5}")
        EndIf
        If $CNT = 15 Then
        If Not WinActive("PHANTASY STAR ONLINE Blue Burst") Then WinActivate("PHANTASY STAR ONLINE Blue Burst")
            Send("{ESC 3}")
            Sleep(500)
            Send("{F4}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(3000)
            Send("{ESC 5}")
        EndIf
        If $CNT = 16 Then
        If Not WinActive("PHANTASY STAR ONLINE Blue Burst") Then WinActivate("PHANTASY STAR ONLINE Blue Burst")
            Send("{ESC 3}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{DOWN 3}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{DOWN}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ENTER}")
            Sleep(500)
            Send("{ESC 3}")
            $CNT = 0
        EndIf
    WEnd
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Edit: Fixed the code because of the mistake I notcied! :whistle:

Edited by Zerohour

Share this post


Link to post
Share on other sites
SmOke_N

lol that was a mistake.... I'll fix it


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Zerohour

That's awsome! Makes me feel good that I'm noticing stuff and learning the code!

and props to quicksilver for helping me understand how the pause func works!

Edited by Zerohour

Share this post


Link to post
Share on other sites
Zerohour

rons with your code I'm getting a new error

Error reading the file:

GUICONSTANTS.AU3

Any info on fixing?

Share this post


Link to post
Share on other sites
Valuater

I thought you wanted to stay hidden (no gui).. so i did this

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused, $bLoop, $cnt = "", $text
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F1}", "ShowMessage")  


; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will open an input box where you can start or stop a script to feed your mag in PSO:BB.  " & @CRLF & @CRLF & "   Please press yes to  *Run*  the program  ")

; Check the user's answer to the prompt (see the help file for MsgBox return values)
; If "No" was clicked (7) then exit the script
If $answer = 7 Then
    MsgBox(4096, "AutoIt", "OK.  Bye!", 1.5)
    Exit
EndIf


Call("ShowMessage")


While $bLoop = 1
    
    $cnt = $cnt + 1
    if $cnt = 5 then
        Send("{ESC 3}")
        Sleep(500)
        Send("{F4}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(3000)
        Send("{ENTER}")
        Sleep(3000)
        Send("{ENTER}")
        Sleep(3000)
        Send("{ESC 5}")
    EndIf
    If $cnt = 16 then
        Send("{ESC 3}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{DOWN 3}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{DOWN}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{ENTER}")
        Sleep(500)
        Send("{ESC 3}")
    EndIf
    if $cnt > 17 then
        $cnt = 0; Reseting Timer            
    EndIf
WEnd

; Print the success message
MsgBox(4096,"AutoIt Example", "Script Stoped.", 4)


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()

    $text = InputBox("AutoIt Example", "Please type in the word ""start"" to initialize or ""stop"" to halt and close the sctipt.")
    If @error = 1 Then
        MsgBox(4096, "Error", "You pressed 'Cancel' - Closing!", 3)
         $bLoop = 0
    EndIf
    If $text = "stop" Then
        MsgBox(4096, "AutoIt", "OK.  Bye!", 1.5)
        Exit
    EndIf 
    If $text = "start" Then
        MsgBox(4096, "Initalizing", "Starting the script - Here we go!")
        WinActivate ("PHANTASY STAR ONLINE Blue Burst")
        $bLoop = 1
        $cnt = 0
    EndIf
EndFunc


; Finished

but ron got there first too.... dag nabbit

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites
SmOke_N

What version are you using? How did you install it? Is you input folder in the correct spot?

On my computer it's: C:\Program Files\AutoIt3\Include


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.