electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Is this a sensible way to write a menu in ChucK?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Fri Jan 18, 2008 6:00 am    Post subject: Is this a sensible way to write a menu in ChucK? Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Fri Jan 18, 2008 6:23 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Jan 18, 2008 6:41 am    Post subject: Reply with quote  Mark this post and the followings unread

<<<"yes, or like this", "">>>;
_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Fri Jan 18, 2008 7:03 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks guys! Very Happy

Rhys
Back to top
View user's profile Send private message
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Fri Jan 18, 2008 9:54 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Jan 18, 2008 12:05 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Fri Jan 18, 2008 12:18 pm    Post subject: Reply with quote  Mark this post and the followings unread

Embarassed

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 Sad
Back to top
View user's profile Send private message
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Mon Jan 21, 2008 7:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

is Std.atoi() what you are looking for? documented here:
http://chuck.cs.princeton.edu/doc/program/stdlib.html

spencer
Back to top
View user's profile Send private message
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Tue Jan 22, 2008 3:43 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use