Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Menu Efficiently
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
BigBear




PostPosted: Tue Feb 19, 2008 10:10 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
riveryu




PostPosted: Tue Feb 19, 2008 10:42 pm   Post subject: 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




PostPosted: Wed Feb 20, 2008 3:37 pm   Post subject: 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




PostPosted: Wed Feb 20, 2008 3:46 pm   Post subject: Re: Menu Efficiently

You can make a function:

Turing:

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


The character for a newline is "\n".
BigBear




PostPosted: Wed Feb 20, 2008 3:53 pm   Post subject: Re: Menu Efficiently

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




PostPosted: Wed Feb 20, 2008 3:54 pm   Post subject: Re: Menu Efficiently

ericfourfour @ Wed Feb 20, 2008 3:46 pm wrote:
You can make a function:

Turing:

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




PostPosted: Wed Feb 20, 2008 7:39 pm   Post subject: 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




PostPosted: Wed Feb 20, 2008 10:22 pm   Post subject: RE:Menu Efficiently

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




PostPosted: Thu Feb 21, 2008 11:04 am   Post subject: 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




PostPosted: Thu Feb 21, 2008 2:50 pm   Post subject: RE:Menu Efficiently

select by clicking and option of 1-5??

pick one way; text based or graphical?
BigBear




PostPosted: Thu Feb 21, 2008 3:28 pm   Post subject: 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




PostPosted: Thu Feb 21, 2008 5:18 pm   Post subject: 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




PostPosted: Thu Feb 21, 2008 5:21 pm   Post subject: 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




PostPosted: Thu Feb 21, 2008 5:34 pm   Post subject: Re: Menu Efficiently

Make one array for every menu. To get the length of an array use the length function. Here is an example:
Turing:
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




PostPosted: Thu Feb 21, 2008 5:36 pm   Post subject: 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?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: