Jump to content

Local


Drakath

Recommended Posts

What is more efficient:

This:

function showMoney(source) 
    local playermoney = getPlayerMoney ( source ) 
    outputChatBox(playermoney) 
end 

or this:

function showMoney(source) 
    outputChatBox(getPlayerMoney ( source )) 
end 

Is it worth storing something in local if you are gonna use it only once?

Link to comment

Well, it would make your script more readable but every time you create a variable it stores it in the memory so technically speaking I guess it would be more efficient if you didn't assign a variable to it. Either way the performance isn't going to increase/decrease greatly so do whatever you prefer :P

Link to comment
  • Moderators

Well if you wanted to know that:

local player = getRandomPlayer () 
  
  
--test 1 --  
local timeNow = getTickCount() 
  
function setMoney1() 
    local playermoney = getPlayerMoney ( player ) 
    setPlayerMoney(player,playermoney) 
end 
  
for i=1,100000 do 
    setMoney1() -- call the function 
end 
outputChatBox(getTickCount()-timeNow .. " ms (with variable)") 
------------ 
  
  
-- test 2 -- 
local timeNow = getTickCount() 
  
function setMoney2() 
    setPlayerMoney(player,getPlayerMoney ( player )) 
end 
  
for i=1,100000 do 
    setMoney2() -- call the function 
end 
outputChatBox(getTickCount()-timeNow .. " ms (without variable)") 
------------ 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...