Sign in to follow this  
Followers 0
Toast

[Error] "Func" statement has no matching "EndFunc"

23 posts in this topic

Hey, I'm very new to the whole scripting scene and yesterday my friend had told me about autoit so I gave it a try. I've been messing with it for a couple of hours now and I've been trying to create a simple hotkey thing but I keep getting the error "Func" statement has no matching "EndFunc" for some reason. I'm not sure why though.

Remember, I'm very new to this so I know the code isn't exactly optimized or anything.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Func Main()

;GUI
    local $Width = 400, $Length = 400
    local $Parent, $Start, $Pause, $Close
    $Parent = GUICreate("Hotkey for GTA", $Witdh, $Length)
    GUISetIcon(@SystemDir & "C:\Program Files\Rockstar Games\GTA San Andreas\samp.exe", 0)
    WinGetPos($parent)
    GUISetState()
    
;HotKeys
    HotKeySet("{F1}", "F1")
    HotKeySet("{F2}", "F2")
    HotKeySet("{F3}", "F3")
    
;Buttons
    $Start = GUICtrlCreateButton("Start", 10, 50, 20, 20)
        GUISetOnEvent($Start, "onstart")
    $Pause = GUICtrlCreateButton("Pause", 80, 50, 20, 20)
        GUISetOnEvent($Pause, "onpause")
    $Close = GUICtrlCreateButton("Close", 150, 50, 20, 20)
        GUISetOnEvent($Close, "OnClose")
        
        GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
        
;Functions  
    Func onstart()
            Func F1()
                Send("/getcrate")
                Sleep(100)
                Send("crack")
            EndFunc
            
            Func F2()
                Send("/me Looks around")
            EndFunc
            
            Func F3()
                Send("/time")
            EndFunc
    EndFunc
    
    Func onpause()
        While
            $Pause = NOT $Pause
            sleep(100)
            ToolTip("Hotkey is paused", 800, 200)
        Wend
    EndFunc
EndFunc

I think there are a bunch of other ways of doing this without using GUISetOnEvent, but I'm not sure about how to do those. Also I have a question about the "$Pause = NOT $Pause" Thing, I just put it like that because I saw it done that way on an example. Yeah so remember I'm fairly new to this and there are probably errors all over the place, so that's why I need help.

PS: I was going to use this for a game and see if it would work that way. Oh and hey :)

Share this post


Link to post
Share on other sites



You can't declare function within function, it's a global rule not only for AutoIt. How ever, you can call a function from within a function body.

Run "SyntaxCheck prod" before any attempt to run your code to allow this tool to inspect the source and find hidden syntax error because you have some here and there, it's Ctrl+F5 to run the check and F5 to execute the code.

Share this post


Link to post
Share on other sites

Oh, really? Alright thanks. What do you mean by that Authenticity? What's a function body?

Share this post


Link to post
Share on other sites

Everything that resides between the Func <function name>() and the matching EndFunc keyword.

Share this post


Link to post
Share on other sites

Everything that resides between the Func <function name>() and the matching EndFunc keyword.

Oh that's what you mean. I don't really know what the meanings of some words are but I do check almost every function I see on the autoit website so I can know what they do. And I already know a little about If and other satements (if they're called that) from working with lua. Anyways I changed a couple of things and removed a couple of things, but now the GUI doesn't even show up, well it does for a second and then the program quits.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

;GUI
    $Parent = GUICreate("Hotkey for GTA", 400, 400)
    GUISetIcon(@SystemDir & "C:\Program Files\Rockstar Games\GTA San Andreas\samp.exe", 0)
    WinGetPos($parent)
    GUISetState()
    
;HotKeys
    HotKeySet("{F1}", "F1")
    HotKeySet("{F2}", "F2")
    HotKeySet("{F3}", "F3")
    
;Buttons
    local $Pause = GUICtrlCreateButton("Pause", 10, 50, 20, 20)
        GUISetOnEvent($Pause, "onpause")
    local $Close = GUICtrlCreateButton("Close", 80, 50, 20, 20)
        GUISetOnEvent($Close, "OnClose")
        
        GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
        
;Functions  
    Func F1()
        Send("/getcrate")
        Sleep(100)
        Send("crack")
    EndFunc

    Func F2()
        Send("/me Looks around")
    EndFunc

    Func F3()
        Send("/time")
    EndFunc

    Func onpause()
        While
            $Pause = NOT $Pause
            sleep(100)
            ToolTip("Hotkey is paused", 800, 200)
        Wend
    EndFunc
    
    Func OnClose()
        Exit
    EndFunc

I'm not getting errors anymore but it's starting and closing a second later.

Share this post


Link to post
Share on other sites

Search the help file for the GuiCreate function, there are a few examples in the bottom of the page which demonstrate how to create a GUI program. Basically, you need a message loop or any loop that will hold your program from starting, executing the code and exit because that is exactly what you're doing right now... Long story short, read the help file ;]

Share this post


Link to post
Share on other sites

Sorry for double post but I can't edit my last post for some reason. Anyways I've fixed all the syntax errors that I had or whatever you call it, but it still only launches for a second then exits. I tried it without the GUI and it still does the same thing, and I'm not sure what to do now.

Here is the hotkey with a GUI

#include <GUIConstantsEx.au3>

Global $Pause

Opt("GUIOnEventMode", 1)

;GUI
    $Parent = GUICreate("Hotkey for GTA", 400, 400)
    GUISetIcon(@SystemDir & "C:\Program Files\Rockstar Games\GTA San Andreas\samp.exe", 0)
    WinGetPos($parent)
    GUISetState()
    
;HotKeys
    HotKeySet("{F1}", "F1")
    HotKeySet("{F2}", "F2")
    HotKeySet("{F3}", "F3")
    
;Buttons
    local $Pause = GUICtrlCreateButton("Pause", 10, 50, 20, 20)
        GUISetOnEvent($Pause, "onpause")
    local $Close = GUICtrlCreateButton("Close", 80, 50, 20, 20)
        GUISetOnEvent($Close, "OnClose")
        
        GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
        
;Functions  
    Func F1()
        Send("/getcrate")
        Sleep(100)
        Send("crack")
    EndFunc

    Func F2()
        Send("/me Looks around")
    EndFunc

    Func F3()
        Send("/time")
    EndFunc

    Func onpause()
        $Pause = NOT $Pause
        While $Pause
            sleep(100)
            ToolTip("Hotkey is paused", 800, 200)
        Wend
    EndFunc
    
    Func OnClose()
        Exit
    EndFunc

And here is it without the GUI

Global $Pause

;HotKeys
HotKeySet("{F1}", "F1")
HotKeySet("{F2}", "F2")
HotKeySet("{F3}", "F3")
HotKeySet("{F5}", "onpause")
HotKeySet("{DEL}", "OnExit")

;Functions
Func F1()
    Send("/getcrate")
    Sleep(100)
    Send("crack")
EndFunc

Func F2()
    Send("/me Looks around")
EndFunc

Func F3()
    Send("/time")
EndFunc

Func onpause()
    $Pause = NOT $Pause
    While $Pause
        sleep(100)
        ToolTip("Hotkey is paused", 800, 200)
    Wend
EndFunc

Func OnExit()
    Exit
EndFunc

I'm not sure why they start and then stop in less than a second after I start them.

Share this post


Link to post
Share on other sites

it seems to me you have no WHILE loop... you need a while loop OUTSIDE the function UNLESS the whole script is a function, so uhh yeah put:

While 1
   $msg = guigetmsg()
   if $msg = $gui_event_Close then exit
Wend

anywhere NOT in the funtion , i owuld put it before the funtions it just seems neater

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Search the help file for the GuiCreate function, there are a few examples in the bottom of the page which demonstrate how to create a GUI program. Basically, you need a message loop or any loop that will hold your program from starting, executing the code and exit because that is exactly what you're doing right now... Long story short, read the help file ;]

Ohhhh, thank you, I don't know why I didn't think about that before. Alright I had a look at it and it's using GUIGetMsg(). I remember reading somewhere that if GUIOnEventMode is on then you can't use GUIGetMsg. So does that mean I would have to rewrite that part and use those Case things instead? Edited by Toast

Share this post


Link to post
Share on other sites

Yup, if you're making a button or a combo box and using Opt('GuiOnEventMode', 1) you need to call GuiCtrlSetOnEvent() for every control that you wish to react to upon event because, again as stated in the help file, you can't use GuiGetMsg with this option (GuiOnEventMode).

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

hey i was intrested in this code im also farly new to autoit so this is what i come up with i dont know if it works or not the changes ive done are in the script

its prety messy but im not getin errors and i also dont have gta so i cant test it but give it a go anyway

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)
Main()

Func Main()

;GUI
    global $Parent, $Start, $Pause, $Close;global instead of local
    
    $Parent = GUICreate("Hotkey for GTA", 155, 40);changed size of window
    GUISetIcon(@SystemDir & "C:\Program Files\Rockstar Games\GTA San Andreas\samp.exe", 0)
    WinGetPos($parent)
    GUISetState(@SW_SHOW);set the state better
    
;HotKeys
    HotKeySet("{F1}", "F1")
    HotKeySet("{F2}", "F2")
    HotKeySet("{F3}", "F3")
    
;Buttons
    $Pause = GUICtrlCreateButton("Pause",5, 5,70,30);changed ur button sizes
        GUISetOnEvent($Pause, "onpause")
    $Close = GUICtrlCreateButton("Close",80, 5, 70, 30)
        GUISetOnEvent($Close, "OnClose")
        
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents");added this
    
    While 1
        Sleep(10);so the window stays open
    WEnd
EndFunc
     ;seperated all ur functions



F3()
Func F3()
    Send("/time")
EndFunc

F2()
Func F2()
    Send("/me Looks around")
EndFunc

F1()
Func F1()
    Send("/getcrate")
    Sleep(100)
    Send("crack")
EndFunc

OnClose()
Func OnClose();changed this
    Exit
EndFunc 

onpause()
Func onpause();changed this
  Do
      sleep(100)
  Until onpause()
  
EndFunc

SpecialEvents()
Func SpecialEvents();added this


    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
    EndSelect

EndFunc
Edited by zac23

Share this post


Link to post
Share on other sites

Nice, you need to fix to calls and it should function properly. Replace the two calls for GUISetOnEvent() to GUICtrlSetOnEvent() and the third one should remain as it is.

Share this post


Link to post
Share on other sites

do u mean like this authenticity?

;Buttons
    $Pause = GUICtrlCreateButton("Pause",5, 5,70,30);changed ur button sizes
        GUIctrlSetOnEvent($Pause, "onpause")
    $Close = GUICtrlCreateButton("Close",80, 5, 70, 30)
        GUIctrlSetOnEvent($Close, "OnClose")
        
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents");added this
    
    While 1
        Sleep(10);so the window stays open
    WEnd
EndFunc

brettf yea i dont know im farly new so how would u script it?


Share this post


Link to post
Share on other sites

Yeah.

This:

OnClose()
Func OnClose();changed this

Does no harm but it's useless because the function get called starting from the first line of code of the function body "Exit" and it's also the last line the get executed in that function or the whole code as well.

Coding style is the issue here because you don't need to enter a Select...Case block if you're testing only one statement, use If ... Then ... structure instead.

All in all, this script is more for a message loop GUI.

Share this post


Link to post
Share on other sites

ohhh ok well thaks for the tips i hope some of this got through to toast lol


Share this post


Link to post
Share on other sites

Alright, I think I understand what you guys were talking about and I changed all the functions to a Select thing instead of all those functions. I also added a While loop too like you guys said. I also removed the hotkeys for now and replaced it with GUI buttons because I wasn't sure if the variable I had set to HotKetSet would work with GUIGetMsg. Yeah so now I have this, but still nothing shows up when I run the script, why?

#include <GUIConstantsEx.au3>

Global $Pause

Opt("GUIOnEventMode", 1)

    While 1
        $msg = GUIGetMsg()
        Sleep(100)
        
        If $msg = $GUI_EVENT_CLOSE then ExitLoop
    WEnd
    GUIDelete()
    
Func Main()

    Local $Pause, $Close, $msg, $Key1, $Key2, $Key3

;GUI
    $Parent = GUICreate("Hotkey for GTA", 400, 400)
    GUISetIcon(@SystemDir & "C:\Program Files\Rockstar Games\GTA San Andreas\samp.exe", 0)
    WinGetPos($parent)
    GUISetState(@SW_SHOW)
        
;Buttons
    $Pause = GUICtrlCreateButton("Pause", 10, 50, 20, 20)
    $Close = GUICtrlCreateButton("Close", 80, 50, 20, 20)
    $Key1 = GUICtrlCreateButton("Key1", 150, 50, 20, 20)
    $Key2 = GUICtrlCreateButton("Key2", 220, 50, 20, 20)
    $Key3 = GUICtrlCreateButton("Key3", 290, 50, 20, 20)

        Select

            Case $msg = $Pause
                $Pause = NOT $Pause
                    While $Pause
                        Sleep(100)
                        ToolTip("Hotkey is paused", 800, 200)
                        GUISetState($GUI_DISABLE)
                    WEnd
                    ToolTip("")
            Case $msg = $Key1
                Send("n")
                Sleep(100)
                Send("/getcrate")
                Sleep(100)
                Send("crack")
            Case $msg = $Key2
                Send("n")
                Sleep(100)
                Send("/me looks around")
            Case $msg = $Key3
                Send("n")
                Sleep(100)
                Send("/time")
        EndSelect
EndFunc

Also if anyone could tell me how I could create a pause type thing that would disable the GUI within the While $Pause. Oh and explain why you need to have the whole while 1 thing for GUI's.

Share this post


Link to post
Share on other sites

I'm still having issues fixing it so I'm just going to bump the thread. Anyways the issue I had is that It starts it doesn't show up, and I even have GUISetState to @SW_SHOW and I also have the While loop

While 1
        $msg = GUIGetMsg()
        Sleep(100)
        
        If $msg = $GUI_EVENT_CLOSE then ExitLoop
    WEnd
    GUIDelete()

I'm still not sure what's wrong with it.

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  
Followers 0