K3STROS Posted October 14, 2015 Share Posted October 14, 2015 So i am very new to this but im sorta catching on pretty quick but one thing i have yet to find out is, how do i open up a new .au3 from a function that is activated by using a button from a GUI scrip. If that didnt make sense maybe this will Player Selection GUI.au3What i want to do is to have these buttons activate a different function depending on what the User clicksSo my idea is it would look something like this, When user would click on #1 another GUI would appear and ask for a USERNAME Choose Name P1.au3 which i think i have scripted properly since is runsFunc OnePlayer()Run " Choose Name P1.au3" iknow this isnt the actual function but i dont know what it is...EndFuncFunc TwoPlayer()Run " Choose Name P2.au3" EndFunc etcetera etcetera...Havent found any help with this anywhere so it must just be a newby thingThanks for any help Player Selection GUI.au3 Choose Name P1.au3 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2015 Moderators Share Posted October 14, 2015 K3STROS,Welcome to the AutoIt forums.Why bother opening a new script? Just combine the 2 scripts into a single one. I suggest you read the Managing Multiple GUIs tutorial in the Wiki to see how it is done.And given the titles of your scripts, please read the Forum rules before posting again to make sure you stay within them.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
K3STROS Posted October 14, 2015 Author Share Posted October 14, 2015 (edited) So this is what i have got so far... Could someone please let me know what im doing wrong at this point? The next thing that should be poping up depending on which of the 4 buttons you click should be another GUI with 1-4 input boxes for player names, but then nothing happens... Ive been going at it for a couple hours and i really feel like a moron. Thanks in advanceexpandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\k3stros\desktop\programs\my game\gui's\start.kxf $Launch_Game = GUICreate("PLAY or NAH", 212, 155, 302, 218) GUISetBkColor(0x00FF00) $PlayButton = GUICtrlCreateButton("PLAY", 0, 0, 209, 73, $WS_GROUP) GUICtrlSetFont(-1, 24, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x0000FF) $ExitButton = GUICtrlCreateButton("EXIT", 0, 80, 209, 73, $WS_GROUP) GUICtrlSetFont(-1, 26, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0xFF0000) $EndGameLabel = GUICtrlCreateLabel("(TERMINATE PROGRAM)", 40, 128, 131, 17, $SS_CENTER) GUICtrlSetBkColor(-1, 0xFF0000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $PlayButton $Number_of_Players = GUICreate("Number Of Players", 212, 182, -1, -1) $Number_of_Players1 = GUICtrlCreateButton("1", 8, 32, 89, 65, $WS_GROUP) GUICtrlSetFont(-1, 24, 400, 0, "Absolute Zero") $Number_of_Players3 = GUICtrlCreateButton("3", 8, 112, 89, 65, $WS_GROUP) GUICtrlSetFont(-1, 24, 400, 0, "Absolute Zero") $Number_of_Players4 = GUICtrlCreateButton("4", 112, 112, 89, 65, $WS_GROUP) GUICtrlSetFont(-1, 24, 400, 0, "Absolute Zero") $Number_of_Players2 = GUICtrlCreateButton("2", 112, 32, 89, 65, $WS_GROUP) GUICtrlSetFont(-1, 24, 400, 0, "Absolute Zero") $Number_of_Players_Banner = GUICtrlCreateLabel("HOW MANY PLAYERS", 8, 8, 198, 16) GUICtrlSetFont(-1, 10, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x00FF00) GUISetState(@SW_SHOW) Case $ExitButton Exit 1 EndSwitch WEnd While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Number_of_Players1 $P1NamePromptGUI = GUICreate("1 PLAYER", 188, 135, 500, 274) GUISetBkColor(0x0000FF) $Player1Input = GUICtrlCreateInput("PLAYER 1", 8, 8, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x00FFFF) GUICtrlSetCursor(-1, 5) $ConfirmName = GUICtrlCreateButton("Confirm", 40, 96, 105, 33, $WS_GROUP) $CharacterLimit = GUICtrlCreateLabel("7 Characters Max", 24, 72, 136, 25, $SS_CENTER) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $BotLabel = GUICtrlCreateLabel("COMPUTER", 8, 40, 172, 23, BitOR($SS_CENTER, $SS_RIGHT, $SS_GRAYFRAME, $SS_WHITEFRAME, $SS_SIMPLE, $SS_SUNKEN)) GUICtrlSetFont(-1, 16, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0xFF0000) GUISetState(@SW_SHOW) Case $Number_of_Players2 $P2NamePromptGUI_1 = GUICreate("2 PLAYERS", 188, 142, 500, 274) GUISetBkColor(0x0000FF) $Player1Input = GUICtrlCreateInput("PLAYER 1", 8, 8, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x00FFFF) GUICtrlSetCursor(-1, 5) $ConfirmName = GUICtrlCreateButton("Confirm", 40, 104, 105, 33, $WS_GROUP) $CharacterLimit = GUICtrlCreateLabel("7 Characters Max", 24, 80, 136, 25, $SS_CENTER) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $Player2Input = GUICtrlCreateInput("Player 2", 8, 48, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0xFF0000) GUISetState(@SW_SHOW) Case $Number_of_Players3 $P3NamePromptGUI_1_1 = GUICreate("3 PLAYERS", 188, 183, 500, 274) GUISetBkColor(0x0000FF) $Player1Input = GUICtrlCreateInput("PLAYER 1", 8, 8, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x00FFFF) GUICtrlSetCursor(-1, 5) $ConfirmName = GUICtrlCreateButton("Confirm", 40, 144, 105, 33, $WS_GROUP) $CharacterLimit = GUICtrlCreateLabel("7 Characters Max", 24, 120, 136, 25, $SS_CENTER) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $Player2Input = GUICtrlCreateInput("Player 2", 8, 48, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0xFF0000) $Player3Input = GUICtrlCreateInput("player 3", 8, 88, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x00FF00) GUISetState(@SW_SHOW) Case $Number_of_Players4 $P4NamePromptGUI_2 = GUICreate("4 PLAYERS", 188, 239, 500, 274) GUISetBkColor(0x0000FF) $Player1Input = GUICtrlCreateInput("PLAYER 1", 8, 8, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x00FFFF) GUICtrlSetCursor(-1, 5) $ConfirmName = GUICtrlCreateButton("Confirm", 40, 192, 105, 33, $WS_GROUP) $CharacterLimit = GUICtrlCreateLabel("7 Characters Max", 24, 168, 136, 25, $SS_CENTER) GUICtrlSetFont(-1, 14, 400, 0, "Times New Roman") $Player2Input = GUICtrlCreateInput("Player 2", 8, 48, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0xFF0000) $Player3Input = GUICtrlCreateInput("player 3", 8, 88, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0x00FF00) $Player4Input = GUICtrlCreateInput("Player 4", 8, 128, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL)) GUICtrlSetFont(-1, 14, 400, 0, "Absolute Zero") GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState(@SW_SHOW) EndSwitch WEnd Edited October 14, 2015 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2015 Moderators Share Posted October 14, 2015 K3STROS,No you are not a moron, but let us stick to just the one thread at a time. And when you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.Now to look at the code....M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2015 Moderators Share Posted October 14, 2015 K3STROS,Here is a working version of your code:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <Array.au3> ; Just to show the array $Launch_Game = GUICreate("PLAY or NAH", 212, 155, 302, 218) $PlayButton = GUICtrlCreateButton("PLAY", 0, 0, 209, 73) $ExitButton = GUICtrlCreateButton("EXIT", 0, 80, 209, 73) GUICtrlCreateLabel("(TERMINATE PROGRAM)", 40, 128, 131, 17, $SS_CENTER) ; No need to store the ControlID if you never use it - and the label is hidden anyway GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $ExitButton Exit Case $PlayButton ; Run the required code in a function _PlayerNumbers() EndSwitch WEnd Func _PlayerNumbers() ; Hide the main GUI GUISetState(@SW_HIDE, $Launch_Game) $Number_of_Players = GUICreate("Number Of Players", 212, 182, -1, -1) $Number_of_Players1 = GUICtrlCreateButton("1", 8, 32, 89, 65) $Number_of_Players3 = GUICtrlCreateButton("3", 8, 112, 89, 65) $Number_of_Players4 = GUICtrlCreateButton("4", 112, 112, 89, 65) $Number_of_Players2 = GUICtrlCreateButton("2", 112, 32, 89, 65) $Number_of_Players_Banner = GUICtrlCreateLabel("HOW MANY PLAYERS", 8, 8, 198, 16) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ; Delete this GUI GUIDelete($Number_of_Players) ; Reshow the main GUI GUISetState(@SW_SHOW, $Launch_Game) ; Exit the function Return Case $Number_of_Players1 ; Call another function and tell it how many players - the names are returned in an array $aPlayers = _PlayerNames(1) ; Just to show the returned array _ArrayDisplay($aPlayers, "", Default, 8) Case $Number_of_Players2 $aPlayers = _PlayerNames(2) ; Just to show the returned array _ArrayDisplay($aPlayers, "", Default, 8) Case $Number_of_Players3 $aPlayers = _PlayerNames(3) ; Just to show the returned array _ArrayDisplay($aPlayers, "", Default, 8) Case $Number_of_Players4 $aPlayers = _PlayerNames(4) ; Just to show the returned array _ArrayDisplay($aPlayers, "", Default, 8) EndSwitch WEnd EndFunc ;==>_PlayerNumbers Func _PlayerNames($iNumber) ; Create arrays to hold the player names and the ControlIDs of the inputs Local $aNames[5] = [0], $aInputs[5] $NamePromptGUI = GUICreate("PLAYER NAME", 188, 240, 500, 274) ; Create the required number of inputs $aInputs[1] = GUICtrlCreateInput("PLAYER 1", 8, 8, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) If $iNumber > 1 Then WinSetTitle($NamePromptGUI, "", "PLAYER NAMES") $aInputs[2] = GUICtrlCreateInput("Player 2", 8, 48, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) EndIf If $iNumber > 2 Then $aInputs[3] = GUICtrlCreateInput("player 3", 8, 88, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) EndIf If $iNumber > 3 Then $aInputs[4] = GUICtrlCreateInput("Player 4", 8, 128, 169, 24, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $WS_BORDER)) GUICtrlSetLimit(-1, 7) EndIf ; Now the other controls $ConfirmName = GUICtrlCreateButton("Confirm", 40, 198, 105, 33) GUICtrlCreateLabel("7 Characters Max", 24, 72, 168, 25, $SS_CENTER) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() ; Confirm pressed Case $ConfirmName ; Set the number of players $aNames[0] = $iNumber ; Set teh chosen player names - you might want to add soem errorchecking to make sure there are names present For $i = 1 To 4 $aNames[$i] = GUICtrlRead($aInputs[$i]) Next ; And now carry on as below ContinueCase Case $GUI_EVENT_CLOSE ; Delete the GUI GUIDelete($NamePromptGUI) ; Return the names Return $aNames EndSwitch WEnd EndFunc ;==>_PlayerNamesPlease ask if you have any questions.And I am working on the assumption that you are writing your own game in AutoIt - if you have not already read the Forum rules to which I linked you above, please do so now as I will not be happy if it turns out that this not the case.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
K3STROS Posted October 14, 2015 Author Share Posted October 14, 2015 Thanks Melba, i appreciate your help, i hadn't actually read the rules, but now i did, i wont post any more game scripts here, thanks for letting me know . I certainly didn't think someone would re-write my code i was expecting someone to know what i was doing wrong, i really appreciate that you went beyond to help now, i can compare! Thanks for all your help.I will defiantly be needing more help in the future. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2015 Moderators Share Posted October 14, 2015 K3STROS, i wont post any more game scripts hereGood to know. I will defiantly be needing more help in the future.And as long as they are within the rules, we will be happy to help you.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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