This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
[Question] +=
Post Reply
Return to board index
Post by
Wildhorn
How in lua do you do a "+=" ?
Like:
local Test = 1
Test += 1
return Test
would output "2".
I tried "+=" and it gave me an error, so i suppose there is another way? Or do I have to do it the long way
local Test = 1
Test = Test + 1
return Test
Post by
Wanderingfox
The long way unless you want to define the operator yourself, and I'm not even sure if that's possible with the sandbox version of lua that wow uses.
edit:
Though you really shouldn't need it unless you're actually using a counter.
For example:
function addOne(input){
local input = input
input = input + 1
return input
}
Is the same as:
function addOne(input){
return input + 1
}
Post by
Wildhorn
Yeah, it was for a counter
Post by
Wanderingfox
You could always do it recursively?
Post by
Wildhorn
Yeah I know, but calling a function just do do Var += 1 seem a bit too much :P
Post by
pelf
The programmer with the most functions on the call stack wins, amirite?
Post by
388951
This post was from a user who has deleted their account.
Post by
RedwoodElf
Lua doesn't implement the increment and decrement operators from C?
Varname++
and
Varname--
won't work?
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.