PDA

View Full Version : Ask for a string then repeat what was typed


soyeah
07-12-2006, 08: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!

lanceA
07-12-2006, 09: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!

Magicplaya
07-13-2006, 10: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".

scooper
07-13-2006, 10: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

Magicplaya
07-13-2006, 11:20 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
Oh I never knew there was a world-level function for concatenating two things in Alice. Thanks!

lanceA
07-13-2006, 11:20 AM
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.:)

Magicplaya
07-13-2006, 11:39 AM
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".

lanceA
07-13-2006, 02: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.