lorcanO33
lorcanO33

Reputation: 32

Actionscript Multi-Dimensional Quiz Engine

This is my engine for a quiz app but I've noticed that I couldn't assign more than one answers for one question without making a complete mess.

answer[0] = ["Green", "Blue", "Red"]
answer[0] = "Green" or "Blue" "Red"

I started to look into multi-dimensional arrays but I can't get it to work. Please help. Here's my engine:

answer = new Array()
answer[0] = "Green"; //THIS IS LIMITED as there are more answers like red or blue
answer[1] = "2"; //Only one answer
question = new Array();
question[0] = "What colours are in the Rainbow";
question[1] = "1+1";
index = 0;

onEnterFrame = function ()
{
    question_txt.text = question[index];
};



enter1.onRelease = function()
{
    if (answer_input.text == answer[index])
    {
        index++;
        answer_input.text = "";
    }
    else
    {
        answer_input.text = "Incorrect";
    }
};

Upvotes: 0

Views: 95

Answers (1)

user151496
user151496

Reputation: 1985

answer[0] = ["Green", "Blue", "Red"];

..then the condition shall look like this:

enter1.onRelease = function(){

  var good=false;
  for(var i=0;i<answer[index].length;i++){
    if(answer[index][i]==answer_input.text){
      good=true;
    }
  }

  if(good){
    index++;
    answer_input.text = "";
  else{
    ...
  }

Upvotes: 1

Related Questions