Weird (bugs?) or something with Input Boxes

Started by Raggit, Tue 08/07/2003 23:54:52

Previous topic - Next topic

Raggit

I decided I want my players to be able enter their names in my game.  When they do this, NPCs will talk to them and call them by whatever they entered as their name.

Well I'm having some very strange problems.  In the beggening of the game I run the InputBox script.

I understand the deal with the string prompt but what should I use for the string buffer? Then I have a command set to display a message right after entering some text in the input box just to test it. The message should contain whatever the player typed.

Example of my script:
___________________________________

InputBox("Enter your name:",what should go here?");
Display("Welcome, what should go here?);
____________________________________

As you can see, I'm a little (if not alot) confused. I read it over in the manaul several times but I still think I'm doing something wrong. Could you provide me with a little example in the style of what I'm trying to do?

Thanx.  ::)
--- BARACK OBAMA '08 ---
www.barackobama.com

Wolfgang Abenteuer

You could try something like:

string name;
InputBox("What is your name", name);
Display("Welcome, %s", name);

That way, string "name" would be changed to whatever the player typed into the InputBox, and you can just use the string variable %s to display it.

At least I think that's what you mean...

~Wolfgang

Raggit

Yeah, that is what I mean but I seem to be getting errors.

It is like it has to have qoutation marks all around the code. Like this:

string name;
InputBox("Enter your name:","name");
Display("Welcome, name");

Or something similar to that.
And then when it does save, the message is displayed like "Welcome, name". When I tried the % it gave me an error saying something about SCI fonts. It doesn't seem to be recongnizing what I type.

Strange. Is there an alternative way to do this or am I screwed up?
--- BARACK OBAMA '08 ---
www.barackobama.com

TerranRich

#3
Um, it's displaying "Welcome,  name" because you're telling it to display the string "Welcome, name" word for word. Do what Wolfgang posted.

string tehName;
InputBox("What is your name?",tehName);
Display("Welcome, %s",tehName);


First, it creates the string called tehname. Then, it creates an input box with the prompt "What is your name?", where the reply wil be stored into the string "buffer" called tehName. A buffer is merely a parameter that is used for output, not input. Usually, functions take in parameters as input, like MoveCharacter(EGO,123,234,0);, where the inputs are the character name, the coordinates, and whether or not it is direct. But in the case of InputBox, only the frist string, the prompt, is an input. The buffer, tehName, is used for output, where the reply will be stored.

Finally, this code will display the strting "Welcome, " followed by whatever is stored inside the string tehName, which will hopefully be the player's name that he just entered before.

Hope that helps. :)

EDIT:

However, if you want this variable to be used in other scripts in other rooms, make sure you include export string tehName; at the very end of the script in which it's declared, and then import string tehName; at the very beginning of any room scripts that you're going to use that variable. It doesn't have to be called tehName, mind you. It can be called anything you want, just keep in mind that it should probably be unique so that you can remember what it is later on. :)
Status: Trying to come up with some ideas...

Scorpiorus

#4
Just a little correction. You can't export strings at the moment. In order to share literal information between the rooms you should use a GetGlobalString()/SetGlobalString() AGS script functions. :P

But if it's just a name I would suggest you to use character[].name string variable instead (didn't you forget we have one? ;))

Example:

InputBox("What is your name?", character[EGO].name);


this way whenever you need to get player's name just use character[EGO].name var to retrieve one.

Display("Hello, %s!", character[EGO].name);

-Cheers

SMF spam blocked by CleanTalk