Jump to content
Sign in to follow this  
Maris

Is it ok to save objects outside of the functions?

Recommended Posts

For example:

local bd;
local function fnEveryTenMinutes()
	if not bd then
		bd = getPlayer():getBodyDamage();
	end
	.....
end
Events.EveryTenMinutes.Add(fnEveryTenMinutes);

I think it should reduce overhead on api calls.

Share this post


Link to post
Share on other sites

Storing data outside of the function is fine. However, you will not have the most up to date information so make sure you don't use it for something that needs to have the most up to date information.

 

Also, the code example you wrote there will only every get the body damage once. The reason for this is the `if not bd then`. This will only set it on the first pass then ignore setting the value for any other call of that function. This is assuming you don't have another section in the function that sets the value of bd.

 

Edited by Leond

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...