Add Dialog Options

Started by , Wed 02/07/2003 18:08:52

Previous topic - Next topic

Plog

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.

SSH

#1
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.
12

Plog

Sorry I told you I was a newbie but my internet is allways connected soo... yeah. thanks by the way.

Plog

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.

SSH

#4
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);
   }
 }
 

12

Plog

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

Wolfgang Abenteuer

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

Plog

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.

Wolfgang Abenteuer

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

Plog

What do I change the X to though. An what does the int x1 bit mean?

Wolfgang Abenteuer

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

Plog

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?

Wolfgang Abenteuer

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

Plog

Can you tel me what all the numbers stand for.
Because I am seriously bad at this.

Wolfgang Abenteuer

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

TerranRich

All this run-script stuff is covered in the Beginners' FAQ. Have you even tried looking there, Plog? :)
Status: Trying to come up with some ideas...

Plog

Can you just please tell me what each number means becuase Ive searched I cant find anything on this please I beg of you. ???

Wolfgang Abenteuer

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

Plog

Thanks but what is this bit for wouldnt this turn it off again?

}
else {
SetDialogOption (1, 3, 0);
}

Wolfgang Abenteuer

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

Plog

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?

Proskrito

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

Plog

It still dosnt work!!
Naything else wrong or commom problems.

Wolfgang Abenteuer

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

Plog

It wont accept the word value without the x

Wolfgang Abenteuer

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

Plog


Proskrito

#27
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!!

Plog

Thats brilliant thanks. ;D
But wht did it suddenly change to parameter just now?

Proskrito

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

Plog

I want to use this script again so do I put run-script 2 and what else do I change?

Plog

I tryed changing the 1 thats in it to 2 but it sais I ve allready used dialog-request what do I do. ???

Wolfgang Abenteuer

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

Plog

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?

Scorpiorus

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

Plog

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?

Scorpiorus

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?

Plog

The one where it sais request.

Wolfgang Abenteuer

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

Plog

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?

Scorpiorus

If it's not too large maybe you could post the whole global script so we could look at?

Wolfgang Abenteuer

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

Plog

I fixed that problem I hadnt actaully created the option for the dialog yet.  :P
Oopsie.

Plog

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


}

Wolfgang Abenteuer

}
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

SMF spam blocked by CleanTalk