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

NaN error

Explorer ,
Jan 13, 2017 Jan 13, 2017

I get a “Nan” error on score counter to when player has choose level from menu

I made a score counter and if has player start level 1 and if has win,counter is keep working to next level.( Level = frame ) it's not exist any issue so far.

But when player has choice to level on menu and start level 2,counter is not work.Level 2 start from to frame 116.I get a "NaN" error.

I write a code like this scrore frame 1

var Scorecounter:Number = 0;

And Score_t1 it's a dynamic text.Use counter code on frame one

function checkButtonsone():void { if(fisoneclicked21 && fistwoclicked) {  Scorecounter = Scorecounter + 10; Score_t1.text = (Scorecounter).toString();  acmessage.visible = true; acmessage.play();  gotoAndPlay(116);//LEVEL 2 } }

and on level 2

function checkButtonponelev2():void { if(fish1clickedleveltwo && fishtwoclickedleveltwo && fishthreeclickedleveltwo)  { Scorecounter = Scorecounter + 10; Score_t1.text = (Scorecounter).toString();  famessage.visible = true; famessage.play(); } }

I'm not using keyframe beetwen two levels.So score frame continue until last frame.(285)

Message was edited by: Burak Ozyurt / I fix some issue

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

Explorer , Jan 14, 2017 Jan 14, 2017

Here is the Solution.

Well, I've no idea why timeline scripting not working for you (you might want to trace Scorecounter if it inits though), but I can suggest a "global" variable solution. Create a class file ScoreHolder.as and put it in the same folder as your *.fla

package
{
  
public class ScoreHolder
  
{
  
static public var score:Number = 0;
  
}

}

Then import it in any frame where you want to access the score value:

import ScoreHolder;

function checkButtonsone():void
{
  
if (fisoneclicked21 && fi

...
Translate
Community Expert ,
Jan 13, 2017 Jan 13, 2017

where's the level 2 code?

is that in a loaded swf?

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 ,
Jan 14, 2017 Jan 14, 2017

No. Levels are at same time line just start at diffrent frames.

//Score Frame 1 line
var Scorecounter:Number = 0;

I'm using code for each fish like this.

//Fish move code

var b3sekseni:Number=7;

var y3sekseni:Number=8;

var speedyuc:Number=75;

stage.addEventListener(Event.ENTER_FRAME,hareketuc);

function hareketuc(oly:Event) {

    balik3.x+=b3sekseni;

    balik3.y+=y3sekseni;

    if ((balik3.x>=stage.stageWidth-balik3.width/2)|| (balik3.x <= balik3.width/2 )) {

        b3sekseni*=-1;

    }

    if ((balik3.y>=stage.stageHeight-balik3.height/2)|| (balik3.y <= balik3.height/2 )) {

        y3sekseni*=-1;

    }

}

balik3.mouseEnabled = false;

//Enabled for mause

balik1.mouseEnabled = true;

balik2.mouseEnabled = true;

balik3.mouseEnabled = true;

//The fishes stop moving and player make his choice.

stop();

stage.removeEventListener(Event.ENTER_FRAME, hareket);

stage.removeEventListener(Event.ENTER_FRAME, bhareket);

stage.removeEventListener(Event.ENTER_FRAME, hareketuc);

acmessage.visible = false

//Corelattion for true fish

var fisoneclicked21:Boolean = false;

var fistwoclicked:Boolean = false;

balik1.addEventListener(MouseEvent.CLICK, greenButton);

function greenButton(event:MouseEvent):void

{

     

        fisoneclicked21 = true;

        checkButtonsone()

     

}

balik2.addEventListener(MouseEvent.CLICK, redButton);

function redButton(event:MouseEvent):void

{

     

        fistwoclicked = true;

        checkButtonsone()

     

}

function checkButtonsone():void

    {

        if(fisoneclicked21 && fistwoclicked)

        {

         

        Scorecounter = Scorecounter + 10;

        Score_t1.text = (Scorecounter).toString();

     

        acmessage = true;

        acmessage.play();

     

        gotoAndPlay(116);//LEVEL 2

}

}

Taslak_2.png

kglad

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 ,
Jan 14, 2017 Jan 14, 2017

LEVEL 2

// Move code for fish (balik62)

var x6l2eksen:Number=7;

var y6l2eksen:Number=8;

var speedyl6:Number=75;

stage.addEventListener(Event.ENTER_FRAME,hareket6liki);

function hareket6liki(oly:Event) {

    balik62.x+=x6l2eksen;

    balik62.y+=y6l2eksen;

    if ((balik62.x>=stage.stageWidth-balik62.width/2)|| (balik62.x <= balik62.width/2 )) {

        x6l2eksen*=-1;

    }

    if ((balik62.y>=stage.stageHeight-balik62.height/2)|| (balik62.y <= balik62.height/2 )) {

        y6l2eksen*=-1;

    }

}

balik62.mouseEnabled = false;

*** Same codes for Level 2.I was put the score counter code for level 2 at my first message.

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 ,
Jan 14, 2017 Jan 14, 2017

click file>publish settings>swf>and tick 'enable debugging'.  retest.

the problematic line number will be in the error message.

what line of code is mentioned in the error message?

and what did you do to trigger the error message (after going to frame 116)?

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 ,
Jan 14, 2017 Jan 14, 2017

Not exist 'enable debugging' on settings.

Can you watch this video kglad I record my issue.

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 ,
Jan 14, 2017 Jan 14, 2017

'permit debugging'

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 ,
Jan 14, 2017 Jan 14, 2017

Nothing seems to any error

Output

Test Movie terminated.

Debug session terminated.

and no compiler errors.

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 ,
Jan 14, 2017 Jan 14, 2017

i know it's not a compiler error.  it's a runtime error.

restest with debugging enabled and trigger the error and explain what you did to trigger the error.

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 ,
Jan 14, 2017 Jan 14, 2017

Like I say score counter is not counting,if I start at level 2.

I test it with permit debug and output say..

"Test Movie terminated"

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 ,
Jan 14, 2017 Jan 14, 2017

1. copy and paste the error message.

2. how is checkButtonponelev2() called?

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 ,
Jan 14, 2017 Jan 14, 2017

1.     No any error message at nowhere

2

var fish1clickedleveltwo:Boolean = false;

var fishtwoclickedleveltwo:Boolean = false;

var fishthreeclickedleveltwo:Boolean = false;

balik12.addEventListener(MouseEvent.CLICK, f1l2);

function f1l2(event:MouseEvent):void

{

      

        fish1clickedleveltwo = true;

        checkButtonponelev2()

      

}

balik22.addEventListener(MouseEvent.CLICK, f2l2);

function f2l2(event:MouseEvent):void

{

      

        fishtwoclickedleveltwo = true;

        checkButtonponelev2()

      

}

balik32.addEventListener(MouseEvent.CLICK, f3l2);

function f3l2(event:MouseEvent):void

{

      

        fishthreeclickedleveltwo = true;

        checkButtonponelev2()

      

}

function checkButtonponelev2():void

    {

        if(fish1clickedleveltwo && fishtwoclickedleveltwo && fishthreeclickedleveltwo)

        {

                  

        Scorecounter = Scorecounter + 10;

        Score_t1.text = (Scorecounter).toString();

      

        acmessage1.visible = true;

        acmessage1.play();

}

}

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 ,
Jan 14, 2017 Jan 14, 2017

so your problem is solved.

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 ,
Jan 14, 2017 Jan 14, 2017

No.Please watch it video again..if you miss here is. bandicam 2017 01 14 15 31 43 918 - YouTube

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 ,
Jan 14, 2017 Jan 14, 2017

it looks like you're testing a scene instead the entire movie.  test the movie so frame 1 plays before you advance to your 2nd scene.

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 ,
Jan 14, 2017 Jan 14, 2017

The game have a 2 level I test it all scene as you see at the video.First of,I test a game nonstop.Then test level from menu for level 2.
Offcourse it works when I directed to level1 but is not any problem with that.Player has choice starting from level 2 or over.And the counter is not running when player start level 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
Community Expert ,
Jan 14, 2017 Jan 14, 2017

where's that menu located?

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 ,
Jan 14, 2017 Jan 14, 2017

On the "menusec" scene.So it's on diffrent scene

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 ,
Jan 14, 2017 Jan 14, 2017
LATEST

Here is the Solution.

Well, I've no idea why timeline scripting not working for you (you might want to trace Scorecounter if it inits though), but I can suggest a "global" variable solution. Create a class file ScoreHolder.as and put it in the same folder as your *.fla

package
{
  
public class ScoreHolder
  
{
  
static public var score:Number = 0;
  
}

}

Then import it in any frame where you want to access the score value:

import ScoreHolder;

function checkButtonsone():void
{
  
if (fisoneclicked21 && fistwoclicked)
  
{
  
ScoreHolder.score += 10;
  
Score_t1.text = ScoreHolder.score.toString();

  acmessage
.visible = true;
  acmessage
.play();

  gotoAndPlay
(116);//LEVEL 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