%s with Display Speech (SOLVED)

Started by Akumayo, Fri 10/06/2005 19:01:15

Previous topic - Next topic

Akumayo

I feel silly posting this, but for the life of me I can't figure it out.

I need to know how to replace %s with the buffer: name.Ã,  Here's the script:

DisplaySpeech(DAD, "Hiya %s!", name);

It calls "name" an undefined symbol.Ã, 
I've already defined "name" using an Input Box though, here's that script:

string name;
InputBox("Your name?", name);

The thing is, when DAD talks, he says "Hiya !"
It seems like it ignores my %s

What do I need to do?
"Power is not a means - it is an end."

RickJ


Akumayo

okay, new script under interaction Talk to Character, reads:

string name;
DisplaySpeech(DAD, "Hey %s!",  name);
RunDialog(0); 

But he still says, "Hey !"
"Power is not a means - it is an end."

DoorKnobHandle

Yeah, because now your string called "name" is still empty...

Add this:

Code: ags

StrCopy ( name, "Joe" );


between your first and your second line and it will display "Hey Joe!" then.

Of course you can also add your InputBox code instead of the StrCopy to allow the player to type in his name and then have it displayed on the screen in a display box.

Akumayo

In the First Time Player Enters Room script, I already have:

string name;
InputBox ("Your name?", name);
Display("So your name is %s", name);

In this display, "name", appears just as it should.
"Power is not a means - it is an end."

DoorKnobHandle

Then you should read upon "Global Variables"...

What you are doing wrong is you are defining a string variable called "name" in one place of the script and then fill its content with the user typed name from the inputbox. But then when you display your displaybox, you simply define a NEW string variable called "name" again and display it inbetween the "Hey" and the "!". The content of the second string variable is emtpy ofcourse...

What you have to do is edit the global script via the menu and then delete both of your "string name;" lines and one on of those lines ( "string name;" ) at the very beginning of the whole file.

That should work...

Akumayo

Alright, i deleted the two string name; lines and added a string name; line to the pointy tip top of the global script, but now an error comes up:

error in room script
undifined symbol 'name'

I'm still confused a little about your reply, I haven't messed with %s much, only %d
"Power is not a means - it is an end."

DoorKnobHandle

Well, I forgot to mention that you will need to add

Code: ags

import string name;


at the very END of your global script file or in your script HEADER.

Or you could have just read all that in the manual.

Quote
Then you should read upon "Global Variables"...

But it should really work now.

Oh, and %d and %s work the same basically.

Akumayo

hmm....

I put:

import string name;

into my script header, but now there's a new error:

cannot import string; use char[] instead
"Power is not a means - it is an end."

monkey0506

You can't import a string, because it's not technically a defined type.  It's technically an object.  At least in C++ it is, so I'm assuming that's the case here (hence the fact you can't import them or use them within structs...).

Basically you just need to change the "string name" to "char name[200]".  It will still hold up to 200 characters (the same as a string), and you can still do the same things to it, like StrCopy(name, "something").  Then when you import it, "import char name[200]" should work I think.

DoorKnobHandle

Sorry for that, Akumayo, not my day today...

Akumayo

apparently its not AGS's day either, for there is yet another error.  I replaced my import string name; with import char name[200];

Here's the error:

Parse error in expr near 'name'

geesh, I'm thinking about just assigning my character a name ~sigh~
"Power is not a means - it is an end."

monkey0506

Hmm...Maybe you can't import arrays?  But yet it told you to... :o  I'm not sure what's going on then.  Sorry I couldn't help.

Ashen

#13
If it's a character name you're setting, can't you just directly edit the character[CHARID].name string? E.g.:

Code: ags

InputBox("Your name?", character[EGO].name);

...

DisplaySpeech (DAD, "Hiya, %s!", character[EGO].name);



EDIT:
Alternatively, try leaving the [200] off the import/export commands.
I know what you're thinking ... Don't think that.

strazer

Quote from: monkey_05_06 on Fri 10/06/2005 20:58:36
Hmm...Maybe you can't import arrays?  But yet it told you to... :o  I'm not sure what's going on then.  Sorry I couldn't help.

I think you can. Try
  import char name;
so you have

Code: ags

// main script

char name[200];
export name;


Code: ags

// script header

import char name;


And consider Ashen's suggestion.

Goot

You can use a global string. Look them up in the manual.

Akumayo

Ashen, you are amazing!  I never thought of doing something so simple (I over think things)  Thank you so much!  It works perfectly!
"Power is not a means - it is an end."

SMF spam blocked by CleanTalk