Toast Posted February 19, 2009 Share Posted February 19, 2009 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. expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 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. Link to comment Share on other sites More sharing options...
Josbe Posted February 19, 2009 Share Posted February 19, 2009 You can't create a Function inside another Func. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Toast Posted February 19, 2009 Author Share Posted February 19, 2009 Oh, really? Alright thanks. What do you mean by that Authenticity? What's a function body? Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 Everything that resides between the Func <function name>() and the matching EndFunc keyword. Link to comment Share on other sites More sharing options...
Toast Posted February 19, 2009 Author Share Posted February 19, 2009 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. expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 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 ;] Link to comment Share on other sites More sharing options...
Toast Posted February 19, 2009 Author Share Posted February 19, 2009 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 expandcollapse popup#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. Link to comment Share on other sites More sharing options...
CodyBarrett Posted February 19, 2009 Share Posted February 19, 2009 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 [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Toast Posted February 19, 2009 Author Share Posted February 19, 2009 (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 February 19, 2009 by Toast Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 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). Link to comment Share on other sites More sharing options...
zac23 Posted February 19, 2009 Share Posted February 19, 2009 (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 expandcollapse popup#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 February 19, 2009 by zac23 Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 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. Link to comment Share on other sites More sharing options...
BrettF Posted February 19, 2009 Share Posted February 19, 2009 In your script, whats the point of calling every function? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
zac23 Posted February 19, 2009 Share Posted February 19, 2009 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? Link to comment Share on other sites More sharing options...
BrettF Posted February 19, 2009 Share Posted February 19, 2009 Just not calling it.... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Authenticity Posted February 19, 2009 Share Posted February 19, 2009 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. Link to comment Share on other sites More sharing options...
zac23 Posted February 19, 2009 Share Posted February 19, 2009 ohhh ok well thaks for the tips i hope some of this got through to toast lol Link to comment Share on other sites More sharing options...
Toast Posted February 19, 2009 Author Share Posted February 19, 2009 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? expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Toast Posted February 20, 2009 Author Share Posted February 20, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now