The713 Posted February 7, 2007 Posted February 7, 2007 (edited) My Project: I am working on a basic text based game, I like to call the arena, where two character (player versus computer) enter the arena and battle to the death. Its failt basic rules, not much graphics to it yet, but we all have to start with a basic concept before developing details right? the player will be able to choose opponents, gain money, gain eperience, level up, buy better equipment, the basics for now. My Problem: I am working at the beginning and have come acrossed something I cannot figure out, and I have put several hours already into this. The basic File menu I have has three menu items, New Character, Load Character, and exit. I would like the Load Character item to branch out into all the character files found in the Character Library folder. My code so far: CODE; Include Files #include <GUIConstants.au3> #include <File.au3> #include <Array.au3> ; Call For Start Menu Functions To Start The Program SM_Start() Func SM_Start() $StartMenu = GuiCreate("Areana", 640, 500) GuiSetState(@SW_SHOW, $StartMenu) $background = GuiCtrlCreatePic("../MediaLibrary/ArenaBGImage.jpg", 0,0, 640, 480) ;set the image to the background so controls overlap it GuiCtrlSetState(-1, $GUI_DISABLE) $FileMenu = GuiCtrlCreateMenu(" &File ") $FileMenu_Opt1 = GuiCtrlCreateMenuItem("&New Character", $FileMenu, 1) $FileMenu_Opt2 = GuiCtrlCreateMenuItem("&Load Character", $FileMenu, 2) $FileMenu_null = GuiCtrlCreateMenuItem("", $FileMenu, 3) $FileMenu_Opt3 = GuiCtrlCreateMenuItem("E&xit", $FileMenu, 4) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $FileMenu_Opt1 NeedsWork() Case $msg = $FileMenu_Opt2 LoadCharMenu() Case $msg = $FileMenu_Opt3 Exit EndSelect WEnd EndFunc ;filler function for areas that need work or have not been completed Func NeedsWork() MsgBox(48, "Guess What", "This Function Is Still Under Construction.") EndFunc Func LoadCharMenu() $characters = _FileListToArray("../CharacterLibrary", "*") ;testing to see if $counter = 0 While $counter <> _ArrayMax($characters) + 1 MsgBox(0, "Character", $characters[$counter]) $counter = $counter + 1 WEnd EndFunc The characters are reading to the messege box fine, so far everything works as it should, except I would like to get the Load Character menu item to list all avialable characters, even if new ones are created later. Any help is greatly appreciated. Edited February 7, 2007 by The713
cjconstantine Posted February 8, 2007 Posted February 8, 2007 My Project: I am working on a basic text based game, I like to call the arena, where two character (player versus computer) enter the arena and battle to the death. Its failt basic rules, not much graphics to it yet, but we all have to start with a basic concept before developing details right? the player will be able to choose opponents, gain money, gain eperience, level up, buy better equipment, the basics for now. My Problem: I am working at the beginning and have come acrossed something I cannot figure out, and I have put several hours already into this. The basic File menu I have has three menu items, New Character, Load Character, and exit. I would like the Load Character item to branch out into all the character files found in the Character Library folder. My code so far: CODE; Include Files #include <GUIConstants.au3> #include <File.au3> #include <Array.au3> ; Call For Start Menu Functions To Start The Program SM_Start() Func SM_Start() $StartMenu = GuiCreate("Areana", 640, 500) GuiSetState(@SW_SHOW, $StartMenu) $background = GuiCtrlCreatePic("../MediaLibrary/ArenaBGImage.jpg", 0,0, 640, 480) ;set the image to the background so controls overlap it GuiCtrlSetState(-1, $GUI_DISABLE) $FileMenu = GuiCtrlCreateMenu(" &File ") $FileMenu_Opt1 = GuiCtrlCreateMenuItem("&New Character", $FileMenu, 1) $FileMenu_Opt2 = GuiCtrlCreateMenuItem("&Load Character", $FileMenu, 2) $FileMenu_null = GuiCtrlCreateMenuItem("", $FileMenu, 3) $FileMenu_Opt3 = GuiCtrlCreateMenuItem("E&xit", $FileMenu, 4) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $FileMenu_Opt1 NeedsWork() Case $msg = $FileMenu_Opt2 LoadCharMenu() Case $msg = $FileMenu_Opt3 Exit EndSelect WEnd EndFunc ;filler function for areas that need work or have not been completed Func NeedsWork() MsgBox(48, "Guess What", "This Function Is Still Under Construction.") EndFunc Func LoadCharMenu() $characters = _FileListToArray("../CharacterLibrary", "*") ;testing to see if $counter = 0 While $counter <> _ArrayMax($characters) + 1 MsgBox(0, "Character", $characters[$counter]) $counter = $counter + 1 WEnd EndFunc The characters are reading to the messege box fine, so far everything works as it should, except I would like to get the Load Character menu item to list all avialable characters, even if new ones are created later. Any help is greatly appreciated. What about using _FileListToArray() whenever "Load" is selected?
4gotn1 Posted February 9, 2007 Posted February 9, 2007 cjconstanine has a good idea, you could even go as far as just adding the new array field at time of character creation
The713 Posted February 9, 2007 Author Posted February 9, 2007 Thank for the help, Im going to work on this right away. Much appreciative for the replies. Thank cjconstantine and 4gotn1 for the suggestions.
The713 Posted February 9, 2007 Author Posted February 9, 2007 I am reading the file names with the _FileListToArray but I would like the Menu length to change with the amount of files so that all files are listed. Rather tricky for me actually. Im sure the solution will seem simple of only I could figure out what it might look like. So far I can set it up alright but I have to edit the code whenever I want to read more files. GuiCreateMenuItem() for each file. I'm not sure how to set up a dynamic menu. Anymore help?
someone Posted February 9, 2007 Posted February 9, 2007 (edited) OK.... I think I know what your looking to do. Try this out. expandcollapse popup#include <GUIConstants.au3> #include <File.au3> #include <Array.au3> $StartMenu = GuiCreate("Areana", 640, 500) GuiSetState(@SW_SHOW, $StartMenu) $background = GuiCtrlCreatePic("../MediaLibrary/ArenaBGImage.jpg", 0,0, 640, 480) GuiCtrlSetState(-1, $GUI_DISABLE) $FileMenu = GuiCtrlCreateMenu(" &File ") $FileMenu_Opt1 = GUICtrlCreateMenuitem("&New Character", $FileMenu, 1) $FileMenu_Opt2 = GuiCtrlCreateMenu("&Load Character", $FileMenu, 2) $FileMenu_null = GuiCtrlCreateMenuItem("", $FileMenu, 3) $FileMenu_Opt3 = GuiCtrlCreateMenuItem("E&xit", $FileMenu, 4) $characters =_FileListToArray(@ScriptDir, "*.123" ,1);;note @scriptdir, and change as needed) For $i = 1 to $characters[0] $character = StringTrimRight ($characters[$i],4);Trim off extension $characters[$i] = GUICtrlCreateMenuitem($character, $FileMenu_Opt2) Next While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $FileMenu_Opt1 Case $msg = $FileMenu_Opt2 Case $msg = $FileMenu_Opt3 Case $msg = $characters[1] MsgBox(0, "", "You clicked fighter!") Exit EndSelect WEnd I played around with the script to make it a little easier for me, but not too much changed. To make this work I have 2 .123 files at the same location as my desktop. This won't however update that list completely dynamically - you have to close and restart the gui... I know theres a way to do that I can't think of it right now but I'll try to post again if I have time. Also I'm not sure assigning the handles to the menu items is efficient... I'll try to make something better. EDIT: not handles....variables Edited February 9, 2007 by someone While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd
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