Author |
Message |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Fri Jan 18, 2008 6:00 am Post subject:
Is this a sensible way to write a menu in ChucK? |
|
|
Code: |
KBHit CutterMenu;
int Char;
int MenuState;
menu();
fun void menu()
{
<<<"Welcome to Rhys' Menu">>>;
<<<"Select which number you like:">>>;
<<<"[1]">>>;
<<<"[2]">>>;
while (MenuState != 2)
{
CutterMenu => now;
appendChar(CutterMenu.getchar());
}
me.exit(); // Is this sensible having this here or will it reach the end of the function and stop automatically when MenuState == 2?
}
fun void appendChar(int Char)
{
if (MenuState == 0)
{
//<<<Char>>>;
if (Char == 49)
{
<<<"You have chosen 1">>>;
<<<"Would you like to choose yes or no?">>>;
<<<"[Y] or [N]?">>>;
1 => MenuState;
}
if (Char == 50)
{
<<<"You have chosen 2">>>;
2 => MenuState;
programme();
}
}
if (MenuState == 1)
{
if (Char == 121)
{
<<<"YES">>>;
2 => MenuState;
programme();
}
if (Char== 110)
{
<<<"NO">>>;
2 => MenuState;
programme();
}
}
}
fun void programme()
{
<<<"Programme Running">>>;
10::minute => now;
}
|
Also, how do I get rid of those ": (string)" lines that get printed along with the strings? The only way I know of at the moment is to include an integer or other non string!
Thanks,
Rhys |
|
Back to top
|
|
|
Frostburn
Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Fri Jan 18, 2008 6:23 am Post subject:
|
|
|
You can get rid of the :string lines by breaking the string into two or more pieces.
Code: |
<<<"I have something on me.">>>;
<<<"We","do","not!">>>;
//output:
//"I have something on me." : (string)
//We do not!
|
_________________ To boldly go where no man has bothered to go before. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Jan 18, 2008 6:41 am Post subject:
|
|
|
<<<"yes, or like this", "">>>; _________________ Kassen |
|
Back to top
|
|
|
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Fri Jan 18, 2008 7:03 am Post subject:
|
|
|
Thanks guys!
Rhys |
|
Back to top
|
|
|
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Fri Jan 18, 2008 9:54 am Post subject:
|
|
|
OK menu is almost done but......
How do I store an int from more than one character from the keyboard?
So for example the prompt would say:
"Enter an number?"
ChucK then waits for the enter button to be pressed, reads the ascii code and converts it into an integer which it can then store as a variable?
Code: |
if (ASCII == 13)
{
User_Entered_Data => int StoredInt;
}
|
This is usually pretty basic stuff with programming languages but I cant find anything in the examples, or am I not looking hard enough?
Thanks,
Rhys |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Jan 18, 2008 12:05 pm Post subject:
|
|
|
Here you go;
Quote: |
ConsoleInput: interim console input (until file I/O)
(use to be hidden Skot object)
see examples/string/readline.ck |
:¬) _________________ Kassen |
|
Back to top
|
|
|
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Fri Jan 18, 2008 12:18 pm Post subject:
|
|
|
EDIT: There doesnt seem to be a parse int type of thing to convert the string token into an integer? An explicit cast doesnt work either |
|
Back to top
|
|
|
spencer
Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
|
Back to top
|
|
|
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Tue Jan 22, 2008 3:43 am Post subject:
|
|
|
Yes I beleive that should do it.
I should have really have seen that myself but lately I've not been seeing the wood for the trees thanks to many a late ChucKing night working on this project.
Thanks Spencer,
Rhys |
|
Back to top
|
|
|
|