Page 1 of 1

Useing a function to update player level

Posted: Wed Jan 25, 2017 6:20 am
by ExtraTerrestrial
So im working on a hey RPG and I brought a function to figure my level from my experience points but I don't know how to make it so that it updates My Level globally if that makes any sense

Code: Select all

--sets the level based on exp
    function levelCheck(exp,level) 
       repeat 
             c=math.sqrt(exp)-(level*4) 
                if ( c>=1 ) then 
                   level=level+1 
                   print("Congradulations level "..level) 
                end 
       until ( c<1) 
       return level
    end
See if I enter 25 for experience and one for level run the function it will say congratulations level 2 but if after the function I put print level it'll come back one

Re: Useing a function to update player level

Posted: Wed Jan 25, 2017 8:04 am
by raidho36
Function arguments are like locals, if you change one it has no effect on the variable it's copied from. You do return new level at the end, so you can assign your hero's level to that return value.