Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I put an answer in a randon position in a math game?

Engaged ,
Dec 04, 2014 Dec 04, 2014

I have a math game I'm working on and I would like to have the answers appear in random positions. For example:

3 x 11 = ?

9    0    33

The answer is obviously 33, position 3. Right now the answer will appear in position 3 every time.

In the next problem I don't want the answer to appear in the same position. I want it to appear in another position randomly. So for example the next problem will have the answer in position 1:

3 x 4 = ?

12    14     73

I am currently putting the answers in a dynamic text box that is already on the stage. I thought about using an array but I can't figure that part out.

Example screen shot:

Capture22.PNG

TOPICS
ActionScript
498
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2014 Dec 04, 2014

if you have 3 textfields (eg, tf1,tf2,tf3) for the answers, you could use:

var answersA:Array=[[x11,x12,x13],...,[9,0,33],...,[xn1,xn2,xn3]];

where the 3 answer choices for question 1 is x11,x12,x13 and the 3 answer choices for the nth question is xn1,xn2,xn3

you could use:

function displayAnswersF(i:int):void{

// display answers for the ith question

var answerA:Array = answersA;

answerA.shuffle();

tf1.text=answerA[0].toString();

tf2.text=answerA[1].toString();

tf3.text=answerA[2].toString();

}

function shuffle(a:Array) {

    var p:int;

    var t:*;

    var ivar:int;

    for (ivar = a.length-1; ivar>=0; ivar--) {

        p=Math.floor((ivar+1)*Math.random());

        t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 09, 2014 Dec 09, 2014

Thanks. I will try today.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 11, 2014 Dec 11, 2014

What is the syntax below? I've seen the  wildcard "*" used in import statements (import flash.events.*) to bring in all of a class but I've never seen it used with a data type.

Is this saying the "t" can by of any kind of data type?

var t:*;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2014 Dec 11, 2014
LATEST

yes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines