PDA

View Full Version : NaN Help


Mark Aged
12-19-2006, 07:02 PM
Every time I try this code, "_root.jimmysendurance -= "strength";", I get NaN, and not a lowering in jimmysendurance. I know "strength" isn't a number, but shouldn't it work because of the ""s? What am I doing wrong?

Edit: My 1234th post!

phdrummer
12-19-2006, 07:04 PM
go to the freame and put the following codejimmysendurance=0
strength=0then it should work

Mark Aged
12-19-2006, 07:05 PM
I already have all the variables set.

Jacob
12-19-2006, 07:15 PM
Are you saying your are doing:

_root.jimmysendurance -= "strength";?

Cause that would be trying to subtract the word "strength" from jimmysendurance. "strength" is a string, therefore the result is NaN (Not a Number)

If strength is a number then you need to remove the quotes

_root.jimmysendurance -= strength;

phdrummer
12-19-2006, 07:17 PM
o... i thought.... i see where i was wrong.

Malignus
12-19-2006, 07:18 PM
Right, exactly--change "strength" to _root.strength;

Jared
12-19-2006, 07:25 PM
Trying to subtract a variable from a string, well thats a interesting idea:)

Jacob
12-19-2006, 07:30 PM
Actually he's trying to subtract a string from a variable. But yes, interesting in either case.

Jared
12-19-2006, 07:32 PM
Oh I see he really meant to put that as a variable but put quotes around it instead so it would be a string.

Matt
12-20-2006, 06:24 AM
Are you saying your are doing:

_root.jimmysendurance -= "strength";?

Cause that would be trying to subtract the word "strength" from jimmysendurance. "strength" is a string, therefore the result is NaN (Not a Number)

If strength is a number then you need to remove the quotes

_root.jimmysendurance -= strength;
Beat me to it.

Mark Aged
12-20-2006, 08:54 AM
Are you saying your are doing:

_root.jimmysendurance -= "strength";?

Cause that would be trying to subtract the word "strength" from jimmysendurance. "strength" is a string, therefore the result is NaN (Not a Number)

If strength is a number then you need to remove the quotes

_root.jimmysendurance -= strength;

Oh, was thinking that without quotes, it'd be a string. Thanks.

Logic
12-20-2006, 09:15 AM
If you encounter any other problems (though I think that the math operations in Flash automatically do this), you can add this little piece for insurance:

_root.jimmysendurance -= Number(strength);

That will (attempt to) convert strength to a number if it is a string. Let us know if this works for you (either JJ's method, mine, or someone else's).

Mark Aged
12-20-2006, 09:47 AM
Jjcorreia's way worked.