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

Frame Random

Explorer ,
Apr 30, 2013 Apr 30, 2013

game.png

this is my game layout,

this is basicaly match order of names.

but every time when game reload all the display names are randomly placed.

i think frame random could be work but don't want to repeat the frame

anyone can help me !!!!

TOPICS
ActionScript
3.3K
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

correct answers 1 Correct answer

Community Expert , May 01, 2013 May 01, 2013

assign your names to an array, then randomizes the array:

var namesA:Array=["xxx","yyy",etc];

namesA=shuffle(namesA);

// namesA is now randomized.  you can loop through namesA and present the display names randomly.

// nothing needs to be changed below.

function shuffle(a:Array):Array {

    var len:Number = a.length-1;

    for (var ivar:Number = len; ivar>=0; ivar--) {

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

        var t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

    return a;

}

Translate
Community Expert ,
Apr 30, 2013 Apr 30, 2013

what's the problem and what's the game?

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
Explorer ,
May 01, 2013 May 01, 2013

first name come then i click 2 if it's order is correct then go to next name

just like quiz

but every time that names are coming in random that's the problem

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 ,
May 01, 2013 May 01, 2013

assign your names to an array, then randomizes the array:

var namesA:Array=["xxx","yyy",etc];

namesA=shuffle(namesA);

// namesA is now randomized.  you can loop through namesA and present the display names randomly.

// nothing needs to be changed below.

function shuffle(a:Array):Array {

    var len:Number = a.length-1;

    for (var ivar:Number = len; ivar>=0; ivar--) {

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

        var t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

    return a;

}

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
Explorer ,
May 01, 2013 May 01, 2013

so i make all names into movie clip

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 ,
May 01, 2013 May 01, 2013

that doesn't matter for using the code i suggested.

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
Explorer ,
May 01, 2013 May 01, 2013

var namesA:Array=["a1","a2","a3"];

dynamic textfield name namesA

they are shuffling but output is a1,a2,a3 like this

there is only one name a3 then i click on according button if it's right then display next name...

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
Explorer ,
May 01, 2013 May 01, 2013

can we jump Randomly to Frame Labels without Repeats

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 ,
May 01, 2013 May 01, 2013

yes, put the frame labels in an array and apply the shuffle function to that array.

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
Explorer ,
May 01, 2013 May 01, 2013

check this

function shuffle(arr:Array):Void {

  var len:Number = arr.length - 1;

  for (var i:Number = len; i >= 0; i--) {

    var p:Number = Math.floor(Math.random() * (i + 1));

    var t:Object = arr;

    arr = arr

;

    arr

= t;

  }

}

var labels:Array = ["a", "b", "c", "d", "e"];

shuffle(labels);

var currentLabel:Number = 0;

function gotoNextLabel():Void {

  if (currentLabel < labels.length) {

    gotoAndPlay(labels[currentLabel]);

    currentLabel++;

  } else {

    stop();

  }

}

gotoNextLabel();

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
Explorer ,
May 01, 2013 May 01, 2013

in this random frame label code

when i got it right name then how go to next name

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 ,
May 01, 2013 May 01, 2013

call gotoNextLabel() again.

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
Explorer ,
May 01, 2013 May 01, 2013

num_plates.num2.onRelease = function ()

{

    if (names.gotoAndStop("b")) // here names is my movie clip inside a to x frame label

    {

        right.gotoAndPlay(2);

        this.gotoAndStop(2);

        updateScore(500);

        this.enabled = false;

        a = a + 1;

        if (a == 24)

        {

            gotoAndStop("over");

        }

   gotoNextLabel();

    }

    else

    {

        updateScore(-100);

        wrong.gotoAndPlay(2);

    }

    

};

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
Explorer ,
May 01, 2013 May 01, 2013
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
Explorer ,
May 02, 2013 May 02, 2013

i didn't find names position

if (names.labels[0] == "a")//

    {

                    right.gotoAndPlay(2);

        this.gotoAndStop(2);

        updateScore(500);

        this.enabled = false;

        a = a + 1;

        if (a == 24)

        {

            gotoAndStop("over");

        }

                    names.gotoNextLabel();

    } //

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 ,
May 02, 2013 May 02, 2013

your code snippets don't make sense.

you'll need to include more code or clearly explain what you're trying to do.

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
Explorer ,
May 02, 2013 May 02, 2013

it's done!!!

i use this code

if (names.labels[names.currentLabel-1]=="a")

Thank you Kglad once again for your help

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 ,
May 03, 2013 May 03, 2013

you're welcome.

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
Explorer ,
May 09, 2013 May 09, 2013

Hi Kglad

there is somethng problem n shuffle function

that names shuffle but after some clicks they repeat

Please help

on first frame in name movie clip code is

function shuffle(arr:Array):Void {

  var len:Number = arr.length - 1;

  for (var i:Number = len; i >= 0; i--) {

    var p:Number = Math.floor(Math.random() * (i + 1));

    var t:Object = arr;

    arr = arr

;

    arr

= t;

  }

}

var labels:Array = ["a", "b", "c", "d", "e"];

shuffle(labels);

var currentLabel:Number = 0;

function gotoNextLabel():Void {

  if (currentLabel < labels.length) {

    gotoAndPlay(labels[currentLabel]);

    currentLabel++;

  } else {

    stop();

  }

}

gotoNextLabel();

and main time line button on click code is

if (names.labels[names.currentLabel-1]=="a")

    {

                    right.gotoAndPlay(2);

        this.gotoAndStop(2);

        updateScore(500);

        this.enabled = false;

        a = a + 1;

        if (a == 24)

        {

            gotoAndStop("over");

        }

                    names.gotoNextLabel();

    } //

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 ,
May 09, 2013 May 09, 2013

once you hit the end of the array, you should reapply the shuffle function if you want to re-randomize the array.

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
Explorer ,
May 09, 2013 May 09, 2013

in "names" movie clip i have 24 frames and in first frame if they all hit

then game is over.

in trace it's shown (b,g,i,a,v,.....) like this there is no repeatation in

array

but here in between frame is repeat.

how i find the solution.

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
Explorer ,
May 10, 2013 May 10, 2013

once we hit the right match then delete the particuler array

is it possible?

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 ,
May 10, 2013 May 10, 2013

you can remove an array element using the splice method. to remove the first array element, use:

labels.splice(0,1);

to remove the last element:

labels.splice(labels.length-1,1);

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
Explorer ,
May 14, 2013 May 14, 2013

this is working but at one point, array intialized and again shffle the array

i didn't figured out the problem.

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 ,
May 14, 2013 May 14, 2013

what problem are you seeing?

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