Random questions in dialogs

Started by Mats Berglinn, Tue 29/11/2005 07:44:33

Previous topic - Next topic

Mats Berglinn

In my current project I'm going to include some quiz questions that are randomly selected three questions out of twenty (or so, haven't decided the maxium yet). This will happen during a dialog so I'm not sure how to script it.

To explain it a little bit better I'll tell you what I want to happen:

When you choice a particular option in a dialog, the quiz starts. The guys you talking to you ask you a question (a new topic starts for each question) and you get different options of answer depending on the question (regular question have three possible answers while yes and no questions only have two). If you get the correct answer you will get to the next question. If you answer all three questions right, you will get to go to a certain room but if you fail at the question the quiz (conversation) stops and you go to restart the quiz.

By the way, I use AGS version 2.62. Just want you to know so that you'll not bring me the "wrong" scripting.

Ashen

dialog_request and variables.

Basically, when you want the quiz to start, in the dialog script use run-script 1 to call something like:
Code: ags

// top of global script
int run1, run2, run3;

// dialog_request
function dialog_request (int param) {
if (param == 1) {
  //
  //'Picks' the questions, and starts the first one.
  run1 = Random(19); // Random question 1.
  run2 = Random(19); // Random Q2.
  while (run2 == run1) run2 = Random(19); // Checks it won't run the same question twice.
  run3 = Random(19); // Random Q3.
  while (run3 == run1 || run3 == run2) run3 = Random(19); // Again, checks for duplicates
  RunDialog(run1); // Starts Q1
}
if (param == 2) {
  RunDialog(run2);
}
if (param == 3) {
  RunDialog(run3);
}
}

NOTE, this assumes the 'question' dialogs are 0 - 19. If they're not, use (Random(19) + x), where x is the first question dialog.

Then, after the first question, run-script 2 to start the second, the run-script 3 for the third. (If you need more help with run-script and dialog_request look them up in the manual, or on the forums. If you're already using them, just change the param values as needed.)

You could probably also use Random(x) commands to vary the possible answers, if you wanted to. Just write more 'answer' options, turn them all off apart from the right one, then turn on two random ones before you start the dialog.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk