Forum Topic: returning NaN

(112 views • 14 replies)

This topic is 1 page long.

<< < > >>
None

TheSongSalad

Reply To Post Reply & Quote

Posted at: 3/18/09 12:52 PM

TheSongSalad NEUTRAL LEVEL 10

Sign-Up: 01/17/09

Posts: 1,334

can anyone help me with why this returns NaN when it shouldn't?

on(release){
	time = 100;
	idiot = "";
	if(fashScoreDev == Infinity){
		flashScoreDev = 0;
	}
	if(making == true){
		flashDays += 1;
		if(flashDays == daystowork){
			flashScoreFinal = flashScoreDev*(.5+Math.random());
			flashScoreDev = 0;
			trace(flashScoreFinal);
		}else{
			flashScoreDev = (_root.flashSkill/10 + _root.soundSkill/12.5 + _root.artSkill/10 + _root.cSkill/10 + daystomake/10)/6;
			trace(flashScoreDev);
		}
	}
}

None

WolfAkela

Reply To Post Reply & Quote

Posted at: 3/18/09 12:59 PM

WolfAkela LIGHT LEVEL 08

Sign-Up: 12/19/05

Posts: 2,332

fashScoreDev


None

TheSongSalad

Reply To Post Reply & Quote

Posted at: 3/18/09 01:01 PM

TheSongSalad NEUTRAL LEVEL 10

Sign-Up: 01/17/09

Posts: 1,334

... yes i know that flashScoreDev is what returns NaN, but it should be a value. i don't know why it isn't. sorry if i wasn't clear.


None

WolfAkela

Reply To Post Reply & Quote

Posted at: 3/18/09 01:04 PM

WolfAkela LIGHT LEVEL 08

Sign-Up: 12/19/05

Posts: 2,332

fashScoreDev. Misspelled.

if(fashScoreDev == Infinity){

You'd end up multiplying with a null, which should become NaN.


None

mayoarm11

Reply To Post Reply & Quote

Posted at: 3/18/09 01:04 PM

mayoarm11 NEUTRAL LEVEL 17

Sign-Up: 06/13/07

Posts: 1,013

not sure if this'll help you, but NaN stands for Not a Number.

This is put into a variable when you put an illegal content into a variable. For example this would return NaN:

var var1: Number;
var2 = "this is a string";

var1 += var2;

obviously, you can't add a string and a number, and var1 would now contain NaN.

hope this helped. too lazy to check ur code, sorry.

Awesome turret game in the making, featuring 85 uniqe turrets: News post

BBS Signature

None

TheSongSalad

Reply To Post Reply & Quote

Posted at: 3/18/09 01:09 PM

TheSongSalad NEUTRAL LEVEL 10

Sign-Up: 01/17/09

Posts: 1,334

At 3/18/09 12:59 PM, WolfAkela wrote: fashScoreDev

ah, thank you, now i understand. thanks for the help.


None

TheSongSalad

Reply To Post Reply & Quote

Posted at: 3/18/09 01:12 PM

TheSongSalad NEUTRAL LEVEL 10

Sign-Up: 01/17/09

Posts: 1,334

damn, no sorry it still returns NaN. i can't find out why. it's in this part i know

}else{
			flashScoreDev = (flashSkill/10 + soundSkill/12.5 + artSkill/10 + cSkill/10 + daystomake/10)/6;
			trace(flashScoreDev);

because flashDays isn't equal to daystowork....


None

ColdLogic

Reply To Post Reply & Quote

Posted at: 3/18/09 01:18 PM

ColdLogic EVIL LEVEL 19

Sign-Up: 11/12/03

Posts: 524

the first time you posted that you had _root. attached now its gone... maybe that?


None

Cojones893

Reply To Post Reply & Quote

Posted at: 3/18/09 01:23 PM

Cojones893 EVIL LEVEL 22

Sign-Up: 03/09/03

Posts: 2,595

Make sure all your variables are cast as Numbers.


None

TheSongSalad

Reply To Post Reply & Quote

Posted at: 3/18/09 01:28 PM

TheSongSalad NEUTRAL LEVEL 10

Sign-Up: 01/17/09

Posts: 1,334

At 3/18/09 01:18 PM, ColdLogic wrote: the first time you posted that you had _root. attached now its gone... maybe that?

i tried it w/ and w/o the _root. and both didn't work.

At 3/18/09 01:23 PM, Cojones893 wrote:

:Make sure all your variables are cast as Numbers.

yup, here are my vars, posted one frame before:

stop();
Mouse.show();
var flashSkill:Number = 0;
var artSkill:Number = 0;
var soundSkill:Number = 0;
var cSkill:Number = 0;
var time:Number = 100;
var idiot:String = "";
var flashname:String = "";
var daystowork:Number = 0;
var making:Boolean = false;
var flashScoreDev:Number = 0;
var flashScoreFinal:Number = 0;
var flashDays:Number = 0;

None

ColdLogic

Reply To Post Reply & Quote

Posted at: 3/18/09 01:53 PM

ColdLogic EVIL LEVEL 19

Sign-Up: 11/12/03

Posts: 524

are they all declared on the main timeline?


None

kiwi-kiwi

Reply To Post Reply & Quote

Posted at: 3/18/09 01:56 PM

kiwi-kiwi LIGHT LEVEL 08

Sign-Up: 03/06/09

Posts: 645

try tracing all the variables in that statement, maybe it's one of those


None

TheSongSalad

Reply To Post Reply & Quote

Posted at: 3/18/09 01:56 PM

TheSongSalad NEUTRAL LEVEL 10

Sign-Up: 01/17/09

Posts: 1,334

yup. their all on frame two, while the button in question is a part of frame 3.


None

ColdLogic

Reply To Post Reply & Quote

Posted at: 3/18/09 01:59 PM

ColdLogic EVIL LEVEL 19

Sign-Up: 11/12/03

Posts: 524

well im not sure about that other frames thing, but if you declare your vars on the main timeline, im pretty sure you cant access them without haveing _root. in front of them, since there scope is the main timeline and your trying to just access them inside a button.

i would change every reference to a variable in that code to include _root. in front of it, i could be mixed up here but I think that should work.


None

TheSongSalad

Reply To Post Reply & Quote

Posted at: 3/18/09 02:00 PM

TheSongSalad NEUTRAL LEVEL 10

Sign-Up: 01/17/09

Posts: 1,334

At 3/18/09 01:56 PM, kiwi-kiwi wrote: try tracing all the variables in that statement, maybe it's one of those

yup, i think that's it. it came out with

NaN
1
1
1
0.5
undefined

so it's got to be daystomake... ok, i got it now. thanks a load everyone.


All times are Eastern Standard Time (GMT -5) | Current Time: 11:26 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!