This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
emufossum13's profile picture

+=

Started by emufossum13, 18 January 2013 - 02:55 PM
emufossum13 #1
Posted 18 January 2013 - 03:55 PM
I was wondering how I can do += in lua. I want to add a number to a variable without re declaring it. This way that variable will keep the same information.
PixelToast #2
Posted 18 January 2013 - 03:56 PM
normal expressions like (5 - 6) wil work without declaring
the numbers can be replaced with a variables name
Bubba #3
Posted 18 January 2013 - 04:21 PM
@Pixel: You might want to rephrase that… I'm not sure what you're trying to say.

There is no += operator in Lua, but "var = var + 1" is perfectly legal.
theoriginalbit #4
Posted 18 January 2013 - 04:22 PM
what your asking for is a little confusing. As Bubba stated there is no += operator. And even if there was doing
var += 2
actually still 're declares' the variable… its just short-hand for
var = var + 2