• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Run local function

Gaddhuve

Member
Joined
May 6, 2011
Messages
76
Solutions
1
Reaction score
19
First of sorry for the lack of "coding-terms" Im just trying to learn by myself. Im just wondering how to execute a local function the best way. Atm Im running them by addEvents which Im guessing is not optimal. How I do it atm:

Code:
local function testFunction(cid)
//stuff//
end

if player then
addEvent(testFunctuin, 1)
end
end

Any help would be great! :)
 
Solution
a local function is just like a regular function, it's just not added to the global environment
all variables without 'local' in front of them go into the global environment ( _G ) which is a table with all variables and functions available to be used at any time

just call it like you would a normal function
function(args)
in your case:
testFunction(player:getId())
a local function is just like a regular function, it's just not added to the global environment
all variables without 'local' in front of them go into the global environment ( _G ) which is a table with all variables and functions available to be used at any time

just call it like you would a normal function
function(args)
in your case:
testFunction(player:getId())
 
Solution
First of sorry for the lack of "coding-terms" Im just trying to learn by myself. Im just wondering how to execute a local function the best way. Atm Im running them by addEvents which Im guessing is not optimal. How I do it atm:

Code:
local function testFunction(cid)
//stuff//
end

if player then
addEvent(testFunctuin, 1)
end
end

Any help would be great! :)

There's something to use :)
Lua:
function testFunction(cid)
   player = Player(cid)
   if not player then --Player not found, lets abort!!
       return false
   end
   
   level = player.getLevel()
   print("The level is " .. level .. ".")
   return true
end

addEvent(testFunction, player.uid)
 
There's something to use :)
Lua:
function testFunction(cid)
   player = Player(cid)
   if not player then --Player not found, lets abort!!
       return false
   end
  
   level = player.getLevel()
   print("The level is " .. level .. ".")
   return true
end

addEvent(testFunction, player.uid)
Lua:
function testFunction(cid)
   local player = Player(cid)
   if not player then --Player not found, lets abort!!
       return false
   end
 
   local level = player:getLevel()
   print("The level is " .. level .. ".")
   return true
end

addEvent(testFunction, player:getId())
 
Lua:
function testFunction(cid)
   local player = Player(cid)
   if not player then --Player not found, lets abort!!
       return false
   end
 
   local level = player:getLevel()
   print("The level is " .. level .. ".")
   return true
end

addEvent(testFunction, player:getId())
player.uid works as well :)
 
Thanks alot for taking the time in explaining this. Really do appreciate it! And so the learning road continues :)
 
Back
Top