Question about strings...

Started by , Sun 12/01/2003 17:46:25

Previous topic - Next topic

Vincent

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

ratracer

I nvere tried it but I think this should work:


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

character[CHARID].name = name;
...

Vincent

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..

Scummbuddy

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);
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Vincent

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

Dorcan

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();
}

ratracer

Dorcan, I believe what you say but why can't you use character[EGO].name = name; to change the name?
...

Dorcan

#7
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)

Suicidal_Rabbit

#8
Is it possible to use this name string in a dialog??
Please answer with the code
'Sometimes we need insanity to keep us sane.'
http:\\www.snuffy.tk <---- Download the Beta ;)

SMF spam blocked by CleanTalk