A very quick question about Lua and variable reassignment

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: A very quick question about Lua and variable reassignmen

Post 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 ?
User avatar
dizzykiwi3
Citizen
Posts: 58
Joined: Tue Jan 14, 2014 2:03 am

Re: A very quick question about Lua and variable reassignmen

Post 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
User avatar
DaedalusYoung
Party member
Posts: 407
Joined: Sun Jul 14, 2013 8:04 pm

Re: A very quick question about Lua and variable reassignmen

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 58 guests