The first is copying global (maybe upvalue) variables to local variables. This could be a minor optimization in a critical part of the code.
The second is the closest thing Lua has to a ternary conditional operator. The "and" and "or" operators short-circuit: if the first operand to "and" / "or" evaluates to false / true respectively, the expression will return the first operand and the second operand will not be evaluated.
That code is equivalent to this:
Code:
local newGroup
if IsInRaid() then
newGroup = "raid"
elseif IsInGroup() then
newGroup = "party"
else
newGroup = false
end
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Joined: 25 Jan 2006 Posts: 8580 Location: 127.0.0.1
Posted: Mon Jul 23, 2018 5:57 pm Post subject:
First one is generally either done for one of two reasons:
1. The vars are within a module.
2. The vars are used to make ease of calling of a function.
In your case, it looks more like the first, or just bad coding in general. When you define a module in Lua, the globals are moved into your modules table, meaning that they technically 'break' for normal usage. More info on that: http://lua-users.org/wiki/LuaModuleFunctionCritiqued
Module creation like this shouldn't be used anymore though since it is deprecated at this point. _________________
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum