Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Thu 28/09/2006 15:49:52

Title: Dialog multiple choices problem
Post by: on Thu 28/09/2006 15:49:52
I have a dialog, where my character must answer three questions correct. Only then, when all three answers will be correct, can he proceede.
Ok, well this is the code:

//main global script file

                .
                .
                .

function obstacle() {

  if ( (dprvo.GetOptionState(3)) && (ddrugo.GetOptionState(2)) && (dtretje.GetOptionState(2)) ) {
   cMoj.Say("All answers corect.");
   cMoj.ChangeRoom(4);
   }
   else {
   cMoj.Say("Wrong answers.");
   }
}

#sectionstart character1_a  // DO NOT EDIT OR REMOVE THIS LINE
function character1_a() {
  // script for Character 1 (Model): Talk to character

obstacle(); 
}
#sectionend character1_a  // DO NOT EDIT OR REMOVE THIS LINE

---------------

Even if the answers are false, the character says "All answers correct."
What must I do, that the game will look the ELSE part of the IF statement?
Title: Re: Dialog multiple choices problem
Post by: strazer on Thu 28/09/2006 16:04:53
  if ( (dprvo.GetOptionState(3)) && ...

Writing the conditional statement like that only means it checks if the return value is "not zero", i.e. "!= 0".

But the Dialog.GetOptionState function has the enum return values eOptionOff, eOptionOn and eOptionOffForever. Yes, these enums represent numbers internally, which is why you don't get an error message, but you can't be sure what number they are and if they are non-zero.

So you have to explicitly write it like this:

  if ( (dprvo.GetOptionState(3) == eOptionOffForever) && ...
Title: Re: Dialog multiple choices problem
Post by: Khris on Thu 28/09/2006 16:11:41
It doesn't work like this.
Dialog.GetOptionState() returns if the option is turned on or off.

Create 3 dialogs, one for each question, then run the first one.
In the dialog scripts, add a set-globalint x 1 to the correct answer, where x is the number of an unused global int.
Then add a goto-dialog x after each option where x is the number of the next dialog.

In the third dialog, don't goto-dialog x but run-script 1, then stop.

Choose Script -> dialog request from the menu, then add something like this:
function dialog_request(int param) {
Ã, if (param==1) {
Ã,  Ã, if (GetGlobalInt(11) && GetGlobalInt(12) && GetGlobalInt(13)) { Ã, // all question answered correctly
Ã,  Ã,  Ã, cMoj.Say("All answers correct.");
Ã,  Ã,  Ã, player.ChangeRoom(4);
Ã,  Ã, else
Ã,  Ã,  Ã, cMoj.Say("Wrong answers.");
Ã, }
}
Title: Re: Dialog multiple choices problem
Post by: on Thu 28/09/2006 16:37:06
Ok, now it displays an error message, when I try to run the game. It says:"parse error at 'else' "

I wrote everything like you did (KhrisMUC)

Is this okay?

// dialog script file
@S  // dialog startup entry point
MOJ: "Koliko dni ima teden?"
return

@1  // option 1


goto-dialog 2
@2  // option 2

goto-dialog 2

@3  // option 3

set-globalint 11 1  //I mean this part ofcourse

goto-dialog 2
----------------------


yeah, well I thought so, because it's more than one sentence. Ok, Thanx to both of you

Ok, now it works fine, but if my answers are wrong, cMoj doesn't say "Wrong answers.", he doesn't say anything, but he says "All answers correct." if I my answers are correct.

Oh, well...
Title: Re: Dialog multiple choices problem
Post by: Khris on Thu 28/09/2006 16:46:16
Looks fine to me.
About the error: I've forgotten a } after "player.ChangeRoom(4);"
Title: Re: Dialog multiple choices problem
Post by: strazer on Thu 28/09/2006 17:06:12
Quote from: KhrisMUC on Thu 28/09/2006 16:11:41It doesn't work like this.
Dialog.GetOptionState() returns if the option is turned on or off.

Ok, I assumed s/he turns off the respective dialog options when the correct answer has been chosen.
Title: Re: Dialog multiple choices problem
Post by: Khris on Thu 28/09/2006 18:01:20
I was writing my first post here while you answered, so that sentence was meant for Lubenc :)