Jump to content

which way better


tipforeveryone
 Share

Recommended Posts

I wonder how the performance is in 2 ways of using variables in lua.

Which one is better when there are many of pivots which can be attached script, each script has its own "self." variables

Method 1: Use table for everything

Script.table = {} --create masster table of scripts

function Script:Start()
  table.category1 = {}
  table.category1.variable_1 = somevalue
  table.category1.variable_2 = somevalue
  ...
  table.category1.variable_n = somevalue

  table.category2 = {}
  table.category2.variable_1 = somevalue
  table.category2.variable_2 = somevalue
  ...
  table.category2.variable_n = somevalue
end

Method 2: Use Script.variable only

Script.valuable_1 = something
Script.valuable_2 = something

function Script:Start()
	self.valuable_3 = something
	self.valuable_4 = something
	...
	self.valuable_n = something
end

 

Link to comment
Share on other sites

The second one will be imperceptibly faster, but it's also less code to write. If you absolutely needed to categorize things you could just name the variable something like self.categoryname_valuename.

  • Thanks 1
  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
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.

 Share

×
×
  • Create New...