Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Ask for a string then repeat what was typed
Old
soyeah
Guest
 
Status:
Posts: n/a
Default Ask for a string then repeat what was typed - 07-12-2006, 09:16 PM

I've been banging my head trying to fig this out. I have to ask now.

In an Alicev2.0 world,

How do I have my character ask for a string (users name) then after user types it in, repeat what was typed in a hello message?

example:
Alice character: What is your name?
**string box appears. User types in name
Alice: Hello _entered string_ .


Thanks so much for any help!
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 07-12-2006, 10:41 PM

soyeah -
Try first creating a variable, call it sName or something, and make it of type Other - String. Create this in your world.myfirstmethod, if possible. Newly created variables appear immediately below the world.myfirstmethod line in the Editor, or whatever method was active when you created the variable.

Now select your new variable and drag it into the method. Select set value and then default string.

In the functions tab under world's details, drag "ask user for a string". Change the question to something like: "Enter your name". Now when the user enters their name, it will be stored in your variable sName. The code should resemble something like the following:
sName set value to ask user for a string question = Enter your name:

After the user types something it will be stored in your variable sName or whatever you named it when you created it.

I hope this helps!
   
Reply With Quote
Old
Magicplaya
Guest
 
Status:
Posts: n/a
Default 07-13-2006, 11:06 AM

Thanks for the tips LanceA!

I tried it out and it worked great. The only thing i'm not sure how to do is to make the string repeated in a sentence. For example, "hello world.sName". Instead of just "world.sName".
   
Reply With Quote
Old
scooper
Guest
 
Status:
Posts: n/a
Default 07-13-2006, 11:34 AM

You may wish to use the world-level function "a joined with b" as a means to combine (concatenate) strings.

I tried it out with the text property of a 3D text object I added to a world.

Steve
   
Reply With Quote
Old
Magicplaya
Guest
 
Status:
Posts: n/a
Default 07-13-2006, 12:20 PM

Quote:
Originally Posted by scooper
You may wish to use the world-level function "a joined with b" as a means to combine (concatenate) strings.

I tried it out with the text property of a 3D text object I added to a world.

Steve
Oh I never knew there was a world-level function for concatenating two things in Alice. Thanks!

Last edited by Magicplaya; 07-13-2006 at 12:23 PM.
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 07-13-2006, 12:20 PM

scooper's suggestion works great, Magicplaya! I added a character Object, aliceLiddell, to my world. I then dragged the object's SAY-method tile into the editor, dragged the world's function a joined with b tile into the parameter of the SAY tile and now after the user enters their name my object says, "How are you feeling today, Bob".

This could lead to an Alice version of an old text based game with a doctor/patient discussion.
   
Reply With Quote
Old
Magicplaya
Guest
 
Status:
Posts: n/a
Default 07-13-2006, 12:39 PM

Quote:
Originally Posted by lanceA
scooper's suggestion works great, Magicplaya! I added a character Object, aliceLiddell, to my world. I then dragged the object's SAY-method tile into the editor, dragged the world's function a joined with b tile into the parameter of the SAY tile and now after the user enters their name my object says, "How are you feeling today, Bob".

This could lead to an Alice version of an old text based game with a doctor/patient discussion.
Yep, I just tried it out too! This could also lead to a good way for users to interact with a movie by setting various character's names before the start for example.

Edit: Is there a way to make it so that the string is not case sensitive? I'm using an If/Else statement after the user inputs a name. So if the user inputs "Bob", the object will say "Hey Bob", otherwise say "Hello Bob". But when the animation is tested, if the user puts in "bob", it will default to "Hello bob" because of the lowercase "b".

Last edited by Magicplaya; 07-13-2006 at 12:50 PM.
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 07-13-2006, 03:04 PM

The only way I know of to do that would be by manipulating the ASCII values of the characters, however I haven't found a way in Alice to grab the first letter of a string (something like a substring() method), and then determine its ascii value. For instance 'B' is 66 and 'b' is 98 in ascii. Alice's boolean comparison functions appear to only function with numerics.

A string is nothing more than an array of characters, each having its own index/element. But I haven't been successful when trying to use Alice's array visualization object as a work around for something such as this.

Maybe someone else either has the answer or has a work-around for this.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2022, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.