Aller au contenu

Photo

Random questions script


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
El Condoro

El Condoro
  • Members
  • 148 messages
I suspect this is really easy but I am stuck. I want players to have to answer a random question posed by a door to get it to open. All is working fine with the door - locked, plot, conversation triggers as it should. The problem is with the script. The example below has 3 questions with 3 choices each. Eventually there will be dozens - ideally the list should be unlimited.

The problem I have is randomly selecting the question and its associated answers. I can enter the declared string values, as shown and the conversation works properly, but I can't figure out how to return sQ3, sQ3a, sQ3b, sQ3c, as their associated text, rather than as "sQ3" etc.

Basically, the idea is that the Random(int numQs) - in this case 3 - will determine the declared string values to use from the list. Anyway, here's the script as it is. Any suggestions welcome. Cheers.

// This script sets the random question used in maze conversations
// with doors or guards
// int numQs == number of questions to choose from in the list (top down)
void main(int numQs)
{
 object oPC = GetPCSpeaker();
 object oDoor = OBJECT_SELF;
 // Question 1
 string sQ1 = "What is a noun?";
 string sQ1a = "An action or doing word";
 string sQ1b = "A naming word for a thing";
 string sQ1c = "A word that describes a thing";
 string sQ1_ans = sQ1b;
 
 // Question 2
 string sQ2 = "What is a verb?";
 string sQ2a = "An action or doing word";
 string sQ2b = "A naming word for a thing";
 string sQ2c = "A word that describes a thing";
 string sQ2_ans = sQ2a; 
 
 // Question 3
 string sQ3 = "What is an adjective?";
 string sQ3a = "An action or doing word";
 string sQ3b = "A naming word for a thing";
 string sQ3c = "A word that describes a thing";
 string sQ3_ans = sQ3c; 
 
 // Calculations
 int iQuestion = Random(numQs);
 string sQuestionNum = IntToString(iQuestion);
 string sQuestion = sQ3; <= These should be arrived at by script rather than hardcoded as here
 string sQuestionA = sQ3a; <=
 string sQuestionB = sQ3b; <=
 string sQuestionC = sQ3c; <=
 string sAnswer = sQ3_ans; <=
 
 // Returned values
 SetCustomToken(100,sQuestion);
 SetCustomToken(200,sQuestionA);
 SetCustomToken(300,sQuestionB);
 SetCustomToken(400,sQuestionC);
 
}
 

#2
El Condoro

El Condoro
  • Members
  • 148 messages
This forum is great - just posting brings solutions (of sorts). Any better ideas gratefully received but this works.

// This script sets the random question used in maze conversations
// with doors or guards
// int numQs == number of questions to choose from in the list (top down)
void main(int numQs)
{
 object oPC = GetPCSpeaker();
 object oDoor = OBJECT_SELF;
 
 int iQuestion = Random(numQs);
 switch (iQuestion)
 {
 case 0:
 SetCustomToken(100,"What is a noun?");
 SetCustomToken(200,"An action or doing word");
 SetCustomToken(300,"A naming word for a thing");
 SetCustomToken(400,"A word that describes a thing");
 SetLocalString(oDoor,"Answer","A naming word for a thing");
 break;
 case 1:
 SetCustomToken(100,"What is a verb?");
 SetCustomToken(200,"An action or doing word");
 SetCustomToken(300,"A naming word for a thing");
 SetCustomToken(400,"A word that describes a thing");
 SetLocalString(oDoor,"Answer","An action or doing word");
 break;
 case 2:
 SetCustomToken(100,"What is an adjective?");
 SetCustomToken(200,"An action or doing word");
 SetCustomToken(300,"A naming word for a thing");
 SetCustomToken(400,"A word that describes a thing");
 SetLocalString(oDoor,"Answer","A word that describes a thing");
 break; 
 }
 
}
 

#3
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
It seems you have a working solution, so I'm a bit wary of messing things up by making things more complicated, but I've been working on a vaguely similar system using custom tokens, and so have a few ideas.



For your problem, you have a list of questions, and each one of those questions has a set of answers attached to it, only one of which is correct. Most of the answers are repeated over and over again in the list, just attached to different questions.

So, Instead of having a question-and-answer bank, think about having a list of questions and a list of answers. Each entry in your question database will then have a couple of pointers to different answers (i.e. the correct answer and the almost correct answer). Each time the script runs, it picks a question at random, looks up the two associated answers, and then picks two other answers at random to fill out the choices.



So your array of answers would look something like this:

string answer1 = "An action or doing word";

string answer2 = "A naming word for a thing";

string answer3 = "A word that describes a thing";

then your questions:



string question1 = "What is a noun?";

int question1correct = 2;

int question1almost = 3;



string question2 = "What is a verb?";

int question2correct = 1;

int question2almost = 2;



And so on. Such a system is much more complicated to implement, but it allows you to easily add more and more questions and answers, and more importantly, allows you to randomize which wrong answers get offered for each question (as well as how the answers are displayed to the player).

#4
El Condoro

El Condoro
  • Members
  • 148 messages
That sounds more like what I'm looking for, actually. I'll give it some time tonight. Thanks for the suggestion.

#5
The Fred

The Fred
  • Members
  • 2 516 messages
You could simply do this through the conversation. It might not be what you want, but if you have all the question nodes with a random check on them (there's a random conditional script, though I forget the name) so the first has a 1/X chance of happening, then the next a 1/(X-1) until the last one always happens (if non of the ones above it happen) then they will all occur randomly. Of course, this might make it a little more awkward to add questions since you'll need to add more conversation nodes, and it would be harder to ensure the same question doesn't come up twice.

#6
El Condoro

El Condoro
  • Members
  • 148 messages
Yeah, I did think about that but the time and effort to type in so many questions into nodes is far greater than a flat text file. I have created an Excel spreadsheet that concatenates the questions and answers into the correct script format, which I then just cut and paste into the script used by the generic conversation, Works a treat.

#7
The Fred

The Fred
  • Members
  • 2 516 messages
OK, that's pretty cool.