Discuss Scratch

kaelo14
Scratcher
4 posts

Variable's value only showing up as NaN after I try to change it. (HELP!)

So I am trying to change my money variable but every time I try to change it, I try to subtract from it using:
change [ v] by (-100000)

But every time it comes up as: “NaN”
congyingzhou
Scratcher
1000+ posts

Variable's value only showing up as NaN after I try to change it. (HELP!)

You should decrease the value.
  • change [ v] by (-1)

Last edited by congyingzhou (Aug. 15, 2018 04:46:56)


This is my signature. It appears after I post anything! (I added this for people who thought I was advertising)
and now i have finally removed that line of links, a lot don't work anyway after I unshared a bunch of projects
Oh look a rainbow (I wanted to make my whole signature a rainbow, but busted character limit)
2nd most-poster in Requests (still???), top 20 most-poster overall, 7.3K posts total, 6.5K requests foolproof mind reader??, try to beat the unbeatable tic-tac-toe AI
geek62
Scratcher
100+ posts

Variable's value only showing up as NaN after I try to change it. (HELP!)

NaN is an abbreviation for “not a number”. If your variable had the value “hello” and you try to subtract a number from it, you'll get NaN.
Make sure the variable starts out with a number, and you should be able to subtract from it and get another number:

when green flag clicked
set [Money v] to [100]
kaelo14
Scratcher
4 posts

Variable's value only showing up as NaN after I try to change it. (HELP!)

That still gives me the NaN when I define what the variable is.
deck26
Scratcher
1000+ posts

Variable's value only showing up as NaN after I try to change it. (HELP!)

Share the project please.
TheLogFather
Scratcher
1000+ posts

Variable's value only showing up as NaN after I try to change it. (HELP!)

EDIT: I see you've made another topic about this, and your problem was already answered there:
https://scratch.mit.edu/discuss/post/3220972/

_______________________________



I'm going to hazard a guess that perhaps you included the currency symbol when you set the variable's value?

So maybe you've got something like "set var to [$100]“ in your project…?

If so, that means the variable does not really have a numerical value (it's a ‘string’ of characters rather than a number), and that means you cannot do arithmetic on it.

A variable must have a numerical value if you want to use ”change var by …" on it, so it cannot contain other characters such as the $ symbol, etc.

Last edited by TheLogFather (Aug. 16, 2018 14:54:18)


Siggy the Kumquat slayer:
Main account: DadOfMrLog –– Frameworks for basic pen-rendered 3D in scratch (see studio). Examples:

- - - - 3D Text - - - - - - Simple shapes - - - Controllable structures - - - On the ground - - - - - - In space - - - -

Powered by DjangoBB