Rydextillxixdiex Posted May 23, 2008 Posted May 23, 2008 I need to create a GUI that has 4 buttons, each with different custom Text. Is there a way to assign a function name or signifier of some sort to each button so that the button specific function can later be placed into the base function to be called on? For example: Func start() While 1 Global $show = 0 Global $target = 0x6a0706 MouseClick("Right", 652, 421, 1, 0) Sleep(5000) Join() Sleep(5000) Enter() Sleep(5000) Attack() ;<====== Will be different depending on User Button Input If $show > 0 then ExitLoop WEnd EndFunc I need 4 GUI buttons that will replace the function call "Attack()" with Attack1(), Attack2(), Attack3(), and Attack4() as they are all different. Maybe if each button was assigned a name you could use If $button1 = _______ then Attack1() I'm not sure though, have never done any work with GUIs so i have come to the forums for help! Thanks in Advance everyone. ...will never learn all there is to know about autoit, no worries...i came to the forums :)
Valuater Posted May 23, 2008 Posted May 23, 2008 (edited) Normally when using Autoit on other GUI's it is best to use hot keys... Example ; Press Esc to terminate script, Pause/Break to "pause" Global $Paused HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("{F9}", "Attack") ;;;; Body of program would go here ;;;; While 1 Sleep(100) WEnd ;;;;;;;; Func TogglePause() $Paused = Not $Paused While $Paused Sleep(100) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit 0 EndFunc ;==>Terminate Func Attack() MsgBox(0x0, "Attack", "... Now Attacking ", 3) EndFunc ;==>Attack 8) EDIT After reading your other post.. Use Koda Form Designer ( its in the Scite tools menu) to design the layout of your GUI 8) Edited May 23, 2008 by Valuater
Rydextillxixdiex Posted May 23, 2008 Author Posted May 23, 2008 hehe not what i meant but thanks , lets reword this. I want 4 Buttons in a Pop Up Window, and depending on which button you press it will "Replace" Attack() in the script with a specified function, designed specifically for each button. The idea is that the Func Start() script is still there, however depending on which button is pressed when the script reaches the attack() step, i would like it to be 4 different things depending on the button pressed at the beggining. The GUI button selector would have to pop up as soon as you opened the .Au3/.Exe script, and the the program will start running with your selection placed in the Func start() where Attack() currently is. Hope this makes a little more sense xD. ...will never learn all there is to know about autoit, no worries...i came to the forums :)
SxyfrG Posted May 25, 2008 Posted May 25, 2008 I'd suggest using a variable to determine which function should be called (and using GUICtrlSetOnEvent or GUIGetMsg to set a function for each button which modifies the variable.) For example: Global $Var ;;;Program goes here;;; Func start() While 1 Global $show = 0 Global $target = 0x6a0706 MouseClick("Right", 652, 421, 1, 0) Sleep(5000) Join() Sleep(5000) Enter() Sleep(5000) ;Attack() ;<====== Will be different depending on User Button Input (scrap this) If $Var = 1 Then ;Call a function here ElseIf $Var = 2 Then ;Call a function here ElseIf $Var = 3 Then ;Call a function here ElseIf $Var = 4 Then ;Call a function here Endif If $show > 0 then ExitLoop WEnd EndFunc That should solve your problem My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website
FreeFry Posted May 25, 2008 Posted May 25, 2008 Or he could do a conditional check in his Attack() function instead(my preferred way) call the Attack function with the first parameter set to the Button that was pressed.. something like Attack($button1) and in your Attack function do something like this: Func Attack($iButton) Switch $iButton Case $button1 ; do some action based on button1 Case $button2 ; do some action based on button2 Case $button3 ; do some action based on button3 ;etc. EndSwitch EndFunc
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