Useing a function to update player level

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ExtraTerrestrial
Prole
Posts: 10
Joined: Wed Jan 25, 2017 5:31 am

Useing a function to update player level

Post 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
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Useing a function to update player level

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

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest