

-----------------------------------

BigBear

Tue Feb 19, 2008 10:10 pm


Menu Efficiently

-----------------------------------

While writing a menu for a program I created a new variable for every input and I wrote it fairly quickly so I ended up with a new line for each variable. I am wondering if I should set these variable to "" then I could reuse them in another menu instead of resetting them for the same one. I realize I would not be able to only use one but I could shorten my code and variable list. 

Would using less variable make a more efficient menu?


-----------------------------------

riveryu

Tue Feb 19, 2008 10:42 pm


RE:Menu Efficiently

-----------------------------------

Just an advice from a noob here..

using arrays is easier than using variables?
u can forloop the stuff the user enters into the elements, or forloop them "".

sry if is too obvious...


-----------------------------------

BigBear

Wed Feb 20, 2008 3:37 pm


Re: Menu Efficiently

-----------------------------------

If I did menu like that wouldn't I need to specify the amount of times to run the loop? Why not use loop then exit when the select back whatever that key may be?

O Are u saying to have one loop and when they enter say "1" then stay in loop just put this? but what would I do for menu in a menu like from the main menu going into options and having multiple menus?


-----------------------------------

ericfourfour

Wed Feb 20, 2008 3:46 pm


Re: Menu Efficiently

-----------------------------------

You can make a function:


fcn getWithMessage (msg : string) : string
    put msg
    var input : string
    get : input
    result input
end getWithMessage

The character for a newline is "\n".


-----------------------------------

BigBear

Wed Feb 20, 2008 3:53 pm


Re: Menu Efficiently

-----------------------------------

How will that work if result is another menu make another function?? If so why not use loops and vars?


-----------------------------------

Nick

Wed Feb 20, 2008 3:54 pm


Re: Menu Efficiently

-----------------------------------

You can make a function:


fcn getWithMessage (msg : string) : string
    put msg
    var input : string
    get : input
    result input
end getWithMessage

The character for a newline is "\n".

what?


-----------------------------------

BigBear

Wed Feb 20, 2008 7:39 pm


Re: Menu Efficiently

-----------------------------------

Also if you have pictures for menu headings like when you select Options you see a nice picture of Options should each picture have a separate variable with comment explaining where it is draw etc or should you just have one variable that gets assigned to different picture right before drawing?


-----------------------------------

ericfourfour

Wed Feb 20, 2008 10:22 pm


RE:Menu Efficiently

-----------------------------------

Let's clear this up first: text or graphical menu?


-----------------------------------

BigBear

Thu Feb 21, 2008 11:04 am


Re: Menu Efficiently

-----------------------------------

Well I guess it is text because you select an option by pressing 1-5 or less depending on menu but it is being Font.Drawed and using View.Update. It also changes colours when you scroll the mouse over it and will select it by clicking.


-----------------------------------

syntax_error

Thu Feb 21, 2008 2:50 pm


RE:Menu Efficiently

-----------------------------------

select by clicking and option of 1-5??

pick one way; text based or graphical?


-----------------------------------

BigBear

Thu Feb 21, 2008 3:28 pm


Re: Menu Efficiently

-----------------------------------

You can do either what is the the difference I will say Text because if mouse is click on option the same variable being getched is change to 1-5.


-----------------------------------

ericfourfour

Thu Feb 21, 2008 5:18 pm


Re: Menu Efficiently

-----------------------------------

Will your menu look something like this?

Menu Title
1. Option 1
2. Option 2
...
n. Option n
Please select between 1 and n.

This can be really easy to make. You need to create an array strings containing the options. Then just make a function that takes the array, outputs the options, gets an integer in range, and returns the integer.

I meant weather you are using a command line interface (CLI) or graphical user interface (GUI). A CLI uses put, get and row/column positions. A GUI uses pixels.


-----------------------------------

BigBear

Thu Feb 21, 2008 5:21 pm


Re: Menu Efficiently

-----------------------------------

ok it's CLI but with an array u need to specify the amount of time to do the loop. right? and if you have many options how do u stay in the area like 
1 play
2 2player 
3 etc 
4 options then you select 4 and a new menu appears like 
Options 
1 single player
2 2 player
3 highscores etc 
how do I use an array for multiple menus?


-----------------------------------

ericfourfour

Thu Feb 21, 2008 5:34 pm


Re: Menu Efficiently

-----------------------------------

Make one array for every menu. To get the length of an array use the length function. Here is an example:
proc putArrayLength (a : array 1 .. * of string)
    put length (a)
    for i : 1 .. length (a)
        put "I looped"
    end for
end putArrayLength

var options : array 1 .. 3 of string
options (1) := "play"
options (2) := "2player"
options (3) := "quit"
putArrayLength (options)

You need to make a function that outputs the array and allows the user to select an option number. Have that function return the number the user selected. Use that number to do whatever else you want with your program.


-----------------------------------

BigBear

Thu Feb 21, 2008 5:36 pm


Re: Menu Efficiently

-----------------------------------

Ok I understand but why not just use a loop for every menu then or is it easier to reuse variable. can a be reused for another menu?


-----------------------------------

BigBear

Fri Feb 22, 2008 2:46 pm


Re: Menu Efficiently

-----------------------------------

So back to the original question should I use one variable for input in many different menus or sub menus because it wouldn't be hard and I have too many variables for the same thing ans - ans20  :lol: But then I can't specify where they are used but that doesn't really matter.

Also instead of length I think you meant upper and instead of 
put "I looped"
put a(i)

