Jump to content

Need help With Menus & Arrays


The713
 Share

Recommended Posts

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 by The713
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

OK.... I think I know what your looking to do. Try this out.

#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 by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...