Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Wed 02/07/2003 18:08:52

Title: Add Dialog Options
Post by: on Wed 02/07/2003 18:08:52
Is there a way I can have it so once I have talked to a charcter about a certain topic that I can make it add an extra option to his dialog?
Kepp it as simple as you can im a serious newbie.
Title: Re:Add Dialog Options
Post by: SSH on Wed 02/07/2003 18:19:05
Quote from: Plog on Wed 02/07/2003 18:08:52
Is there a way I can have it so once I have talked to a charcter about a certain topic that I can make it add an extra option to his dialog?

To turn an option on, you put option-on option number in your dialog script. You know, if you read the tutorial in the Help menu, you can find these things out without having to connect to the internet!

Also, you don't need to start a new thread in the forums to ask the same question in a slightly different way. Just reply to the exisinting thread.
Title: Re:Add Dialog Options
Post by: on Wed 02/07/2003 18:22:51
Sorry I told you I was a newbie but my internet is allways connected soo... yeah. thanks by the way.
Title: Re:Add Dialog Options
Post by: on Wed 02/07/2003 18:26:42
I forgot to say the dialog he talks in is different from the one I want to add one in how do I do that.
Title: Re:Add Dialog Options
Post by: SSH on Wed 02/07/2003 18:28:50
No problems. Welcome to using AGS. If you make a really good game, please let us know! Please do read the manual, though!

The thing to remember, as it says in the Beginners forum rules, (which I'm sure that you read before posting  ::) ) Chris Jones, the guy who wrote AGS and lets us have it for free and keeps adding great new features, has to pay for bandwidth used by this site, so it's kinda rude to spend his money on something that you could have found out in the program itself.

On the other hand, if you look at some of the rubbish in the other forums...  ;)

EDIT:
Oh, and you can edit replies to add things or fix mistakes, rather than post multiple one-liners.

To reply to your question about if the option is in a nother topic: well:

1) Does it really need to be another topic?
2) This is a bit mor tricky. You''l need to use:

run-script X        


which runs global text script function "dialog_request", with X passed as the single parameter.

 function dialog_request (int xvalue) {
   if (X==1) {
SetDialogOption (int topic, int option, int new_state);
   }
 }
 

Title: Re:Add Dialog Options
Post by: on Wed 02/07/2003 18:39:45
 :o
Oh I dont get that.
Where exactly do I put it and where do I put the number from which dialog its from and number of option.

Thanks for the welcome. But I could never make a good game Im just re-making one I drew on paper once a while back.
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Wed 02/07/2003 19:10:13
The run-script x line goes under the dialog option you want to have run the script, e.g.:

@S
@1
ego: "Hello"
run-script 1
@2
stop

and the function dialog_request (int x1) { plus the code that SSH gave you goes at the end of your global script.

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Wed 02/07/2003 19:23:30
I put it in and it told me to reaplace the X.
function dialog_request (int x1) {
if (X==1) {
SetDialogOption (int topic, int option, int new_state);
}
}
And that there is a Parse error expr near 'int'
on the setdialog line.
Man this is confusing me.
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Wed 02/07/2003 19:43:57
You need to replace "topic" with the topic number you are referring to, "option" with the dialog option you want to change, and "new_state" with "0" of you want to make the option disappear, "1" if you want to make the option appear, or "2" if you want to make it disappear forever.

So, if you wanted topic #1's dialog option #3 to appear with that code, for example, you'd write:

SetDialogOption (1, 3, 1);

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Wed 02/07/2003 19:48:48
What do I change the X to though. An what does the int x1 bit mean?
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Wed 02/07/2003 20:07:29
You mean the "X==1" or the "x1"?  The "X==1" line that SSH posted means that the variable "X" has to be exactly "1" or else the code will not run.

The "int x1" in the "function dialog_request" line refers to the "run-script 1" line you put in the dialog script.  Had you put "run-script 2", then you would have needed "int x2" instead of "int x1".

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Wed 02/07/2003 20:15:53
Two more questions.
1) It wont accept the X in (X==1) what do I do?

2) How do I make it that a option dosn't show up until that dialog happens?
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Wed 02/07/2003 20:52:26
In order for it to accept the X==1 you need to first declare "X" as an variable by adding int x;.

If you're just using the function as a dialog on/off type function, it might be easier to use GlobalInts rather than normal variables, otherwise you'd have to do variable importing and exporting to be able to access those variables in your global script from local room scripts, whereas GlobalInts take care of that for you.

That might go like this:

(Topic 0)
@S
return
@1 //greet
salesman1: "Hello!"
ego: "I'd like to buy something."
return
@2 //buy steak
salesman: "I don't sell steak, talk to the other salesman."
run-script 1
return
@3
stop

Then at the end of the global script:
function dialog_request (int xvalue) {
if (value == 1)
 SetGlobalInt (0, 1);
}

Finally, in the "talk to character" script for the second salesperson, select "run script", then add the code:

if (GetGlobalInt(0) == 1) {
 SetDialogOption (1, 3, 1);
}
else {
 SetDialogOption (1, 3, 0);
}

Then, the second character's dialog (Topic 1) will look like this:

<Greet> // option 1
<Buy Coffee> // option 2
<Buy Steak> // option 3--will be hidden if the player hasn't asked the first salesperson about "Steak".

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Wed 02/07/2003 21:02:58
Can you tel me what all the numbers stand for.
Because I am seriously bad at this.
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Wed 02/07/2003 21:10:57
My best advice would be to check the Help file in the AGS program.  It lists all of the available functions as well as what all the "int"s represent.  Also, you might want to take a look at the short scripting tutorial (also in the AGS help file) which shows you the basics of assigning variables, if/else statements, GlobalInts, and such.  It can help you get started with AGS scripting.

~Wolfgang
Title: Re:Add Dialog Options
Post by: TerranRich on Thu 03/07/2003 03:26:19
All this run-script stuff is covered in the Beginners' FAQ. Have you even tried looking there, Plog? :)
Title: Re:Add Dialog Options
Post by: on Thu 03/07/2003 17:40:32
Can you just please tell me what each number means becuase Ive searched I cant find anything on this please I beg of you. ???
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Thu 03/07/2003 17:53:56
The SetDialogOption numbers are (int topic, int option, int new_state).

int topic is the topic number of the topic you wish to modify with the script.  You can find this number in the Dialogs tree tab in AGS.

int option is the option number of the topic you selected that you wish to change.  This is also found in the Dialogs tree tab.

int new_state tells AGS whether to turn the option on, off, or off forever.  0 would turn the option off, 1 would turn the option on, and 2 would turn the option off forever.

So, SetDialogOption(0,3,1); would turn on option number 3 in topic 0.

The SetGlobalInt numbers represent the number of the GlobalInt and the value to which it is set.

So SetGlobalInt(0, 1); would set GlobalInt #0 to the value of 1.

The GetGlobalInt numbers check a GlobalInt and see if it is set to a certain value.

GetGlobalInt(0) == 1; checks to see if GlobalInt #0 is equal to 1.

By the way, the AGS help file has a contents index sorted by function.  If you see someone mention GetGlobalInt, for example, then go to the AGS Help menu, click the "Index" tab, then type in GetGlobalInt in the box and press Enter and it will display the function, its parameters, and its usage.  Nearly all of the information you need to successfully use every feature of AGS is in that file.

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Thu 03/07/2003 18:03:58
Thanks but what is this bit for wouldnt this turn it off again?

}
else {
SetDialogOption (1, 3, 0);
}
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Thu 03/07/2003 18:27:38
Sort of.  The "else" means that if GlobalInt 0 is anything other than "1", then the dialogue option will be turned off.  As long as the value of GlobalInt 0 stays at 1, the option will be turned on.  The "else" part just ensures that the option will never come on unless GlobalInt 0 is 1.  That's to prevent the option from staying on if you decide to hide it again later.  Once a dialogue option has been turned on with code, it can only be turned off again with code.  That's what the "else" is for.

If you never plan on changing GlobalInt 0 back to 0 or any other number afterwards, then the "else" line isn't necessary.  I always put one in my scripts just for good measure, though. ;)

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Thu 03/07/2003 18:53:35
Its not working arggh this is what I wrote is there anything wrong?

DIALOG 3:

// dialog script file
@S  // dialog startup entry point
return
@1  // option 1
JAKE: What the hell?
CIRCUM: Pretty please.
JAKE: No you must have a valid reason.
JAKE: Like starting a crew
JAKE: or running erands for the mayor.
run-script 1
stop
@2  // option 2
JAKE: Im not allowed to do that Mr. Stances.
stop
@3  // option 3
JAKE: Well maybe you should plan this better.
CIRCUM: Aww crap!
stop

GLOBAL SCRIPT:

function dialog_request (int x1) {
if (1 == 1)
SetGlobalInt (0, 1);
}

TALK TO CHAR SCRIPT:

 // script for character3: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 2, 1);
}
else {
SetDialogOption (4, 2, 0);
}

I definalty got the right Dialog and Option. What could be the problem?
Title: Re:Add Dialog Options
Post by: Proskrito on Thu 03/07/2003 18:56:08
QuoteGLOBAL SCRIPT:

function dialog_request (int x1) {
if (1 == 1)
SetGlobalInt (0, 1);

1 is ALWAYS equal to 1  ;)
you probably wanted to write:
if (x1==1)

Oh, sorry, it didnt help at all, i didnt read the whole code.
Title: Re:Add Dialog Options
Post by: on Thu 03/07/2003 19:02:22
It still dosnt work!!
Naything else wrong or commom problems.
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Thu 03/07/2003 19:12:03
change this:

function dialog_request (int x1) {
if (1 == 1)
SetGlobalInt (0, 1);
}

to this:

function dialog_request (int xvalue) {
if (value == 1)
SetGlobalInt (0, 1);
}

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Thu 03/07/2003 19:39:08
It wont accept the word value without the x
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Thu 03/07/2003 19:54:31
It may need the "x" then.  I can't remember off the top of my head if it needs to be if (xvalue == 1) {, so try it with the "x" and if that works then it's ok.

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Thu 03/07/2003 19:57:54
Dosnt work either.
Title: Re:Add Dialog Options
Post by: Proskrito on Thu 03/07/2003 19:58:18
try this: (i suppose that the option you want to turn on is #4 and the topic is #1):

// dialog script file
@S // dialog startup entry point
return
@1 // option 1
JAKE: What the hell?
CIRCUM: Pretty please.
JAKE: No you must have a valid reason.
JAKE: Like starting a crew
JAKE: or running erands for the mayor.
run-script 1
stop
@2 // option 2
JAKE: Im not allowed to do that Mr. Stances.
stop
@3 // option 3
JAKE: Well maybe you should plan this better.
CIRCUM: Aww crap!
stop

GLOBAL SCRIPT:

function dialog_request(int parameter){
if (parameter==1) SetDialogOption(1,4,1);
}

And in the "talk to" interaction just the rundialog function.
PS: dont write the  x, you must refer to a varable with the same name you declared it, so if you wrote (int xvalue) you´ll have to write if (xvalue==...)
PS2: Read the manual!! everything is in there clearly explained!!
Title: Re:Add Dialog Options
Post by: on Thu 03/07/2003 20:08:26
Thats brilliant thanks. ;D
But wht did it suddenly change to parameter just now?
Title: Re:Add Dialog Options
Post by: Proskrito on Thu 03/07/2003 20:14:33
its just because i have it that way in my script, but you could replace "parameter" with anything and it would work. (as long as you replace it at the two places with the same word, you know  :))
Title: Re:Add Dialog Options
Post by: on Fri 04/07/2003 17:05:04
I want to use this script again so do I put run-script 2 and what else do I change?
Title: Re:Add Dialog Options
Post by: on Fri 04/07/2003 22:00:56
I tryed changing the 1 thats in it to 2 but it sais I ve allready used dialog-request what do I do. ???
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Sat 05/07/2003 05:51:03
It only allows you to use on function dialog_request(), which is why you typed in a parameter.  If you used Proskrito's script for your first one, your second one should look something like this:

function dialog_request(int parameter){
if (parameter==1) {
SetDialogOption(1,4,1);
}
if (parameter==2) {
//code here
}
}

And then you would use run-script 2 in the dialogue option for the second code.  If you need a third, then just add another if (parameter==#) statement, and so on.  Each parameter # represents the run-script #.

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Sat 05/07/2003 10:22:15
It comes up with a Parse erorr unexpected "if"

GLOBAL:

}
function dialog_request(int parameter){
if (parameter==1) SetDialogOption(4,2,1);
}
if (parameter==2) SetDialogOption(1,3,1);
}

Whats wrong this time?
Title: Re:Add Dialog Options
Post by: Scorpiorus on Sat 05/07/2003 10:42:42
look at Wolfgang's script attentively:

Quote from: Wolfgang Abenteuer on Sat 05/07/2003 05:51:03
function dialog_request(int parameter){
if (parameter==1) {
SetDialogOption(1,4,1);
}
if (parameter==2) {
//code here
}
}

function dialog_request(int parameter) {
if (parameter==1) {
SetDialogOption(4,2,1);
}
if (parameter==2) {
SetDialogOption(1,3,1);
}

} //end of dialog_request()

-Cheers
Title: Re:Add Dialog Options
Post by: on Sat 05/07/2003 10:58:00
All these errors are annoying me it sais Nested functions not supported.

GLOBAL:
 }
function dialog_request(int parameter) {
if (parameter==1) {
SetDialogOption(4,2,1);
}
if (parameter==2) {
SetDialogOption(1,3,1);
}

} //end of dialog_request()

What now?
Title: Re:Add Dialog Options
Post by: Scorpiorus on Sat 05/07/2003 14:26:51
Check the braces...

Every function has to be enclosed by two braces:

function dialog_request() {

...code here...

}

It's not only for dialog_request but every function too.

Btw, what line does it break at?
Title: Re:Add Dialog Options
Post by: on Sat 05/07/2003 17:19:44
The one where it sais request.
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Sat 05/07/2003 18:31:53
If it's giving you the "Nested Functions not supported" error, that means that you've inserted your function dialog_request () { inside the middle of another function.  Look to see if there is a } at the very end of your code (the whole global script, since usually the dialog_request functions are placed at the end of the global script).  If there is, delete that } and move it to the line directly above your function dialog_request () { line and see if that fixes it.

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Sat 05/07/2003 21:02:54
This one wont work its with the same as the original dialog.

 // script for character3: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 2, 1);
}
else {
SetDialogOption (4, 2, 0);
}  
if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 3, 1);
}
else {
SetDialogOption (4, 3, 0);
}
Whats wrong this time?
Title: Re:Add Dialog Options
Post by: Scorpiorus on Sat 05/07/2003 22:12:17
If it's not too large maybe you could post the whole global script so we could look at?
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Sat 05/07/2003 22:14:29
It might be easier to combine those two, since you're using the same GlobalInt and value to do two different things, as such:

if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 2, 1);
SetDialogOption (4, 3, 1);
}
else {
SetDialogOption (4, 2, 0);
SetDialogOption (4, 3, 0);
}
RunDialog(4);

Also, be sure to add the RunDialog(); line I put at the end of the interact with character code or it'll just enable/disable the topics but won't actually bring up the topic.

Was your code giving you an error message or was it just not working (i.e. clicking TALK on the character wasn't producing anything)?

~Wolfgang
Title: Re:Add Dialog Options
Post by: on Sun 06/07/2003 15:11:16
I fixed that problem I hadnt actaully created the option for the dialog yet.  :P
Oopsie.
Title: Re:Add Dialog Options
Post by: on Sun 06/07/2003 15:17:40
Guests cant edit so I have to post again i messed this part up tell me what to do with the } & {s.

}
function character2_a() {
 // script for character2: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (1, 3, 1);
}
 


function character3_a() {
 // script for character3: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 2, 1);
{
if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 3, 1);



function character0_a() {
 // script for character0: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (0, 3, 1);


}
Title: Re:Add Dialog Options
Post by: Wolfgang Abenteuer on Sun 06/07/2003 19:41:51
}
function character2_a() {
// script for character2: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (1, 3, 1);
}
}


function character3_a() {
// script for character3: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 2, 1);
}
if (GetGlobalInt(0) == 1) {
SetDialogOption (4, 3, 1);
}
}


function character0_a() {
// script for character0: Talk to character
if (GetGlobalInt(0) == 1) {
SetDialogOption (0, 3, 1);
}
}

Each if statement needs to be enclosed in brackets, and so does each function.  Look at this:

function character0_a() { first bracket for function
if (GetGlobalInt(0) == 1) { first bracket for if statement
SetDialogOption (0, 3, 1);
} last bracket for if statement
} last bracket for function

As well, if you ever have one function to perform two different things using the exact same criteria, you can combine them into one if statement.  In your function character3_a() { script, you have two different things being done using the same criteria, that being if (GetGlobalInt(0) == 1).  Therefore, the script will do both of those things if GlobalInt 0 is set to 1.  So, you can combine them into one if statement instead of using two.  It would look like this:

if (GetGlobalInt(0) == 1) {
 SetDialogOption (4, 2, 1);
 SetDialogOption (4, 3, 1);
}

It makes the script more organised and easier to follow.  Both ways will work, though, so I guess just go with whatever you're most comfortable.

~Wolfgang