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

Stop math.random generating numbers

Participant ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

Hi,

I have made a test which has a "test over" page at the end. When the test has finished and goes to this page, I cannot get the buttons to work - even though it was using a code snippet. I have noticed that math.random() keeps generating numbers when I get to the "test over" page and wondered if this was the reason why I could not get any buttons to work.

Is there a way to stop math.random() from generating numbers? The code for it is;

var MeSelRam: Number = Math.random();

MeSelectQu = Math.round(MeSelRam * 9 + 1);

Numbers are generated on frame 5. "Test over" is frame 111.

Capture.PNG

Capture2.PNG

On the "test over" frame I tried to use MeSelRam = null; but didn't work.

Views

587

Translate

Translate

Report

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

Participant , Feb 10, 2017 Feb 10, 2017

I've just managed to fix it. I put the math.random() inside of my if statement;

if (MeAnsweredQu == 10) {

  gotoAndStop("MeTestOver")

} else {

  //Selecting random number

  var MeSelRam: Number = Math.random();

  MeSelectQu = Math.round(MeSelRam * 9 + 1);

So now it will only generate if not all 10 questions have been answered. Thanks for both your help

Jack

EDIT: By doing this, it has also allowed my buttons to work on the test over frame!

Votes

Translate

Translate
LEGEND ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

Uh... if you don't want that code to execute more than once, then don't loop to that frame more than once?

That being said, I cannot fathom why you'd think generating a random number would break your buttons. Unless the values of MeSelRam and MeSelectQ are explicitly involved in your button event handler logic, there's no way it's having any effect on them.

Votes

Translate

Translate

Report

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 ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

the following answers your question.  but before employing one of the two snippets read message 1 because there may be some other issue more fundamental than your question indicates.

if you have code in a frame that you only want to execute once AND you need to replay that frame repeatedly, use either:

// 1.

var alreadyExecuted:Boolean;

if(!alreadyExeucted){

alreadyExecuted=true

oneTimeF();

}

function oneTimeF():void{

// the code you want to execute once

}

// or 2.

var alreadyExecuted:Boolean;

if(!alreadyExeucted){

alreadyExecuted=true

// put the code you want to execute once here

}

Votes

Translate

Translate

Report

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
Participant ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

I've just managed to fix it. I put the math.random() inside of my if statement;

if (MeAnsweredQu == 10) {

  gotoAndStop("MeTestOver")

} else {

  //Selecting random number

  var MeSelRam: Number = Math.random();

  MeSelectQu = Math.round(MeSelRam * 9 + 1);

So now it will only generate if not all 10 questions have been answered. Thanks for both your help

Jack

EDIT: By doing this, it has also allowed my buttons to work on the test over frame!

Votes

Translate

Translate

Report

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 ,
Feb 10, 2017 Feb 10, 2017

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

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