Jump to content

Local


Drakath

Recommended Posts

Posted

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?

s.epicrow.com:22003.png

Posted

I don't know if it's "worth", but there's no point if you are just going to use it once.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

  • Moderators
Posted

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)") 
------------ 
  

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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