Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Simple question : Why is my variable not taking away the number?

Asked by
6zk8 95
4 years ago
local m = m - 1000

My variable is not taking away the number. I know this is a simple fix but i tried everything and it doesn't work. Thank you.

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

well you cant do local m = m - 1000 because the variable m is just being declared.. at run time, the statement actually looks like this m = nil - 1000.. so if variable m in m - 1000 was not declared before using it, it should through an error that says attempt to do arithmetic on global m(a nil value or something like that. or sometimes the code will just halt when it reaches that statement.

i recommend doing it like this:

local x = 500 --whatever number you want
local m = x - 1000

the above should work fine b/c x is declared before used, so the statement won't look like this on run time m = nil - 1000

0
it was already decal 6zk8 95 — 4y
0
*declared 6zk8 95 — 4y
0
It just been declared, so m don't has any value. Block_manvn 395 — 4y
1
in that case then do `m = m - 1000` and not `local m = m - 1000` User#23252 26 — 4y
View all comments (2 more)
0
Thanks. It worked. 6zk8 95 — 4y
0
np User#23252 26 — 4y
Ad

Answer this question