I’m new to AS3 and I’m trying to make a multiplication tables review to help kids learn their tables. The app shows a random equation “a * b = c” with four possible answers with randomly generated positions, three of which are randomly generated answers and one right answer and for the most part my code works fine, but im having trouble avoiding any of the three randomly generated answers to be the same as the right answer.
my code is on the timeline, here’s some of it
displayRandomNumber();
var a = wildCardNum;
var b = factorB.text;
var product:Number = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
var answerPositionNumber:Number = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
function displayRandomNumber()
{
var high:Number = 10;
var low:Number = 1;
factorA.text = (Math.floor(Math.random()*(1+high-low))+low).toString();
factorB.text = (Math.floor(Math.random()*(1+high-low))+low).toString();
}
function randomAnswerPosition()
{
if (answerPositionNumber == 1)
{
answerPlace1.text = ""+product;
answerPlace2.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace3.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace4.text = ""+Math.floor(Math.random() * 10) + 1;
}
if (answerPositionNumber == 2)
{
answerPlace2.text = ""+product;
answerPlace1.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace3.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace4.text = ""+Math.floor(Math.random() * 10) + 1;
}
if (answerPositionNumber == 3)
{
answerPlace3.text = ""+product;
answerPlace1.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace2.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace4.text = ""+Math.floor(Math.random() * 10) + 1;
}
if (answerPositionNumber == 4)
{
answerPlace4.text = ""+product;
answerPlace1.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace2.text = ""+Math.floor(Math.random() * 10) + 1;
answerPlace3.text = ""+Math.floor(Math.random() * 10) + 1;
}
}
answerPlaceA.addEventListener(MouseEvent.CLICK, choice1);
function choice1(event:MouseEvent)
{
if(answerPositionNumber == 1 && timer.currentCount <= 3)
{
rw.gotoAndPlay("f");
MovieClip(root).fastRightAnswer+=1;
MovieClip(root).score+=1000;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 1 && timer.currentCount >= 4 && timer.currentCount <=15)
{
rw.gotoAndPlay("r");
MovieClip(root).regularRightAnswer+=1;
MovieClip(root).score+=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 1 && timer.currentCount >= 16)
{
rw.gotoAndPlay("a");
MovieClip(root).slowRightAnswer+=1;
MovieClip(root).score+=250;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else{rw.gotoAndPlay("w");
MovieClip(root).wrong+=1;
MovieClip(root).score-=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
}
answerPlaceB.addEventListener(MouseEvent.CLICK, choice2);
function choice2(event:MouseEvent)
{
if(answerPositionNumber == 2 && timer.currentCount <= 3)
{
rw.gotoAndPlay("f");
MovieClip(root).fastRightAnswer+=1;
MovieClip(root).score+=1000;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 2 && timer.currentCount >= 4 && timer.currentCount <=15)
{rw.gotoAndPlay("r");
MovieClip(root).regularRightAnswer+=1;
MovieClip(root).score+=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 2 && timer.currentCount >= 16)
{rw.gotoAndPlay("a");
MovieClip(root).slowRightAnswer+=1;
MovieClip(root).score+=250;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else{rw.gotoAndPlay("w");
MovieClip(root).wrong+=1;
MovieClip(root).score-=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
}
answerPlaceC.addEventListener(MouseEvent.CLICK, choice3);
function choice3(event:MouseEvent)
{
if(answerPositionNumber == 3 && timer.currentCount <= 3)
{
rw.gotoAndPlay("f");
MovieClip(root).fastRightAnswer+=1;
MovieClip(root).score+=1000;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 3 && timer.currentCount >= 4 && timer.currentCount <=15)
{rw.gotoAndPlay("r");
MovieClip(root).regularRightAnswer+=1;
MovieClip(root).score+=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 3 && timer.currentCount >= 16)
{rw.gotoAndPlay("a");
MovieClip(root).slowRightAnswer+=1;
MovieClip(root).score+=250;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else{rw.gotoAndPlay("w");
MovieClip(root).wrong+=1;
MovieClip(root).score-=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
}
answerPlaceD.addEventListener(MouseEvent.CLICK, choice4);
function choice4(event:MouseEvent)
{
if(answerPositionNumber == 4 && timer.currentCount <= 3)
{
rw.gotoAndPlay("f");
MovieClip(root).fastRightAnswer+=1;
MovieClip(root).score+=1000;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 4 && timer.currentCount >= 4 && timer.currentCount <= 15)
{rw.gotoAndPlay("r");
MovieClip(root).regularRightAnswer+=1;
MovieClip(root).score+=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else if(answerPositionNumber == 4 && timer.currentCount >= 16)
{rw.gotoAndPlay("a");
MovieClip(root).slowRightAnswer+=1;
MovieClip(root).score+=250;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = wildCardNum;
b = factorB.text;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
else{rw.gotoAndPlay("w");
MovieClip(root).wrong+=1;
MovieClip(root).score-=500;
MovieClip(root).subTotalScore.text = "Your score: " +MovieClip(root).score.toString();
nextFrame();
displayRandomNumber();
a = factorA.text;
b = wildCardNum;
product = 0;
factorA.text = String(a);
factorB.text = String(b);
product = a * b;
answerPositionNumber = Math.floor(Math.random() * 4) + 1;
randomAnswerPosition();
timer.reset();
timer.repeatCount = aux+25;
timer.start();
}
}
As I said, I’m new to this… Please shed some light over me… And thank you for any help…