Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Sun 12/01/2003 17:46:25

Title: Question about strings...
Post by: on Sun 12/01/2003 17:46:25
I was wondering if you can put text in a string. like in the beginning there's a question like what is your name, and that becomes the main character's name.

Vincent
Title: Re:Question about strings...
Post by: ratracer on Sun 12/01/2003 19:11:19
I nvere tried it but I think this should work:


string name;
InputBox("What is your name?", name);

character[CHARID].name = name;
Title: Re:Question about strings...
Post by: on Sun 12/01/2003 20:03:29
I tried what you said, the inputbox works. but I don't get how you can display the name after you put it in the string..
Title: Re:Question about strings...
Post by: Scummbuddy on Sun 12/01/2003 21:46:03
Display
Display (string message, ...)

Displays a message to the screen. It will be displayed in the standard message box, and centred in the middle of the screen. You can insert the values of variables using "%d" and "%s" in the message. To insert the value of an integer variable, use %d, to insert a string use %s.
Example:

str maincharname;
Display ("Your name is %s.", maincharname);
Title: Re:Question about strings...
Post by: on Mon 13/01/2003 15:15:27
I tried it, but it only worked within an conversation.
But I want that the game asks at the beginning what my name is.
And then uses it trough the whole game.


Vincent
Title: Re:Question about strings...
Post by: Dorcan on Mon 13/01/2003 16:21:03
If you want to have the player's name written on the top of the screen for exemple, you can make a gui with a Label inside, format a string with the player's name, and display the string in the Label.

Exemple :

First Room script (the one that the game start with)



function GetPlayerName(){
string name;
string S;

  InputBox("What is your name?", name);
  StrCopy(character[EGO].name,name);  //!! You can't do : character.[EGO].name = name;  Use StrCopy() instead.

  Display("Welcome in my game, %s",character[EGO].name);

  StrFormat(S,"Player's name is %s",character[EGO].name);
  SetLabelText(0,0,S); //I assume that it's GUI 0, and the LabelText =#0
  GUIOn(0);  //Display the GUI with the player's name inside
}

function object0_a() { //The player try to open a door
  // script for object0: Interact object
  Display("Sorry %s, but you don't have the key...",character[EGO].name);
}


function room_a() {
  // script for room: First time player enters screen
  GetPlayerName();
}
Title: Re:Question about strings...
Post by: ratracer on Tue 14/01/2003 15:58:25
Dorcan, I believe what you say but why can't you use character[EGO].name = name; to change the name?
Title: Re:Question about strings...
Post by: Dorcan on Tue 14/01/2003 16:32:46
It's a specification of the engine... It doesn't work well when you try to do string1 = string2.

Now, recent versions of the engine report this error when trying to compile the game (except character[EGO].name=name, but it does return nothing, and character[EGO].name has then no value)
Title: Re:Question about strings...
Post by: Suicidal_Rabbit on Mon 21/07/2003 18:47:54
Is it possible to use this name string in a dialog??
Please answer with the code