Page 2 of 2

Re: A very quick question about Lua and variable reassignmen

Posted: Sat Feb 07, 2015 10:27 am
by Roland_Yonaba
Maybe the original question was partially answered, but i'll ask anyway, for my own understanding : why would you want to change the value of a certain variable through a setter function ? Or were you just wondering if it was possible to do so ?

Re: A very quick question about Lua and variable reassignmen

Posted: Sat Feb 07, 2015 7:57 pm
by dizzykiwi3
That still doesn't seem to be working... I'm testing it in the local console of Zerobrane Studio

To be specific I'm trying to do a function like this

Code: Select all

function returntobase(val,i,base)
  if val > base then 
    if val - i < base then
      val = base
    else
      val = val - i
    end
  elseif val < base then 
    if val + i > base then
      val = base
    else
      val = val + i
    end
  end
end
val is going to be a field of a table

Re: A very quick question about Lua and variable reassignmen

Posted: Sat Feb 07, 2015 9:51 pm
by DaedalusYoung
Just return the desired variable in the function.

Code: Select all

x = 5
print(x) --5

x = setvar(x)
print(x) --10

function setvar(z)
    z = 10
    return z
end