Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Suicidal_Rabbit on Wed 23/07/2003 14:48:32

Title: I want to use a string in my dialog
Post by: Suicidal_Rabbit on Wed 23/07/2003 14:48:32
I making a game where you have to fill in your name at the beginning and the game uses this name through the whole game.

I use:

string name;

InputBox("What is your name?", name);
Display ("Your name is %s.", name);

Is there a way to use this in a dialog?
Title: Re:I want to use a string in my dialog
Post by: TerranRich on Wed 23/07/2003 15:00:27
First of all, you need to use the variable called "name" throughout that script. BUT, if you want to keep that variable throughout the game, simply use the character[WHOMEVER].name variable. Like so...

InputBox("What if your name?",character[EGO].name);
Display("Welcome, %s.",character[EGO].name);

And use it throughout, as it is automatically a global variable.
Title: Re:I want to use a string in my dialog
Post by: on Wed 23/07/2003 15:07:52
but is it possible to recall the string in a dialog?
Title: Re:I want to use a string in my dialog
Post by: Al_Ninio on Wed 23/07/2003 15:36:12
Quote from: Dryhump on Wed 23/07/2003 15:00:27
And use it throughout, as it is automatically a global variable.

I think that means "yes".
;)
Title: Re:I want to use a string in my dialog
Post by: Suicidal_Rabbit on Wed 23/07/2003 15:47:11
The dialog doesn't support much what normal scripting does and i've tried it to use it in a dialog but it doesn't work because the character says the scripting code.
Title: Re:I want to use a string in my dialog
Post by: Al_Ninio on Wed 23/07/2003 15:55:00
Woops, apparently I misread your post.
And thus my answer was wrong... Sorry...
I think you'll have to use a-

Run-Script X

function for that.
Look it up in the manual.
Title: Re:I want to use a string in my dialog
Post by: TerranRich on Thu 24/07/2003 01:00:34
And you shouldn't have to ask for help on run-script n as it is fully covered in the Beginners' FAQ, which everybody should have read. :)
Title: Re:I want to use a string in my dialog
Post by: Suicidal_Rabbit on Thu 24/07/2003 16:23:42
I did what the manual said and now I get a parse error when I start the game... could anyone explain the run-script/ dialog_request?
maybe I didn't understand the manual good enough..
Title: Re:I want to use a string in my dialog
Post by: SSH on Thu 24/07/2003 17:48:31
Post your dialog code and your dialog scirpt function
Title: Re:I want to use a string in my dialog
Post by: on Thu 24/07/2003 17:55:06
in global script :

function dialog_request (int 1) {
  DisplaySpeech(EGO,"Hello i'm %s", character[EGO].name);
 }


in dialog script:

run-script 1
Title: Re:I want to use a string in my dialog
Post by: SSH on Thu 24/07/2003 18:12:09
This is the same mistake this guy made:
http://www.agsforums.com/yabb/index.php?board=6;action=display;threadid=7458

also, TerranRich/Dryhump/StopChangingYourName, I was trying to post a link to the part of the FAQ that says about this, but I couldn't find it!

Title: Re:I want to use a string in my dialog
Post by: TerranRich on Fri 25/07/2003 04:00:35
My mistake. I thought it was in there.

I thought the run-script x command was self-explanatory. Never to fear, I will host the Beginners' FAQ myself (so I can change it whenever I want to) and add this in there...




The run-script x command

Whenever you want to run regular AGS script form within a dialog script, simply run the run-script x command, where x is replaced by a number. This will call the global function called function dialog_request(int X) {..., passing X as a parameter.

What does that all mean? Well, It will run the dialog_request global function, and sets X (or whatever you want to call the variable name after the "int" part within the parentheses) to the value that you told it.

Let's say you ran "run-script 5". This would run the global function "dialog_request" and sets the integer variable (in this case, X) to 5. Now, OBVIOUSLY, you would need some way of checking what value X was given when the function is run.

Therefore, we must have a set of if...else if...else if... commands inside the dialog_request function. So, we would have something like this...

function dialog_request(int blah) {
(http://www.harbinger-software.com/images/space.gif)if (blah==0) {
(http://www.harbinger-software.com/images/space.gif)(http://www.harbinger-software.com/images/space.gif)// This code is executed when "run-script 0" is called...
(http://www.harbinger-software.com/images/space.gif)} else if (blah==1) {
(http://www.harbinger-software.com/images/space.gif)(http://www.harbinger-software.com/images/space.gif)// This code is executed when "run-script 1" is called...
(http://www.harbinger-software.com/images/space.gif)} else...
}


Etc., etc.

So, as you see, the code would keep checking for different possible values of X or blah or whatever you want to call it, until it comes across the one that you passed with the "run-script x" command.

Get it? Got it? Good! :)


(Soon to be included in the New AGS Beginners' FAQ) :P