Enabling ObjectManager and Setting Up Unit References
Enabling the ObjectManager
To enable the ObjectManager in your rotation, you need to set LT.UseObjectManager
to true
in your rotation file. This allows the ObjectManager to update and maintain unit information.
-- In your rotation file
LT.UseObjectManager = true
Ensure you set this before any logic that relies on the ObjectManager.
Setting Up Unit References
There are two main ways to set up references to important units like player, target, mouseover, and focus. We'll cover both methods, but recommend using local variables for better performance and scope control.
Method 1: Using Local Variables (Recommended)
This method creates local references to units, which is more efficient and helps prevent global namespace pollution.
---@type Unit
local player = LT.Player --[[@as Unit]]
---@type Unit
local target = LT.Target --[[@as Unit]]
---@type Unit
local focus = LT.Focus --[[@as Unit]]
---@type Unit
local mouseover = LT.MouseOver --[[@as Unit]]
Using local variables improves performance and keeps your code clean. It's the recommended approach for most scenarios.
Method 2: Using Global Variables (For Development Only)
---@type Unit
_G.player = LT.Player --[[@as Unit]]
---@type Unit
_G.target = LT.Target --[[@as Unit]]
---@type Unit
_G.mouseover = LT.MouseOver --[[@as Unit]]
---@type Unit
_G.focus = LT.Focus --[[@as Unit]]
Using global variables (_G
) is not recommended for regular use. It's primarily for debugging and development purposes. Prefer local variables in your rotations.
Accessing Units from Group Arrays
We've implemented a new feature that allows you to access the first valid unit directly from a group array, such as LT.Fgroup.Tanks
. This change simplifies code and makes it more intuitive to work with group-based operations.
How It Works
When you access a property or method on a group array (e.g., LT.Fgroup.Tanks:exists()
), the system:
- Finds the first valid Unit object in the array.
- Returns the requested property or method of that unit.
- If no valid unit is found, it returns
false
forexists
andisvalid
checks, andnil
for other properties.
Usage Examples
Checking if Any Tanks Exist
lua
if LT.Fgroup.Tanks:exists() then
-- There is at least one tank in the group
print("We have a tank!")
end
Accessing Properties of the First Tank
if LT.Fgroup.Tanks:isvalid() and LT.Fgroup.Tanks:incombat() then
-- The first tank is valid and in combat
print("Our tank is fighting!")
end
This approach always operates on the first valid unit in the group. It's still possible to iterate over all units in the group using the Listfunctions
Benefits
- Simplified Code: Treat group arrays as if they were single units, reducing the need for explicit loops or checks.
- Intuitive Syntax: The syntax
LT.Fgroup.Tanks:exists()
feels natural and reads like checking if there are any tanks. - Consistent Behavior: Ensures consistent behavior whether you're working with individual units or groups.
This feature is particularly useful for quick checks or when you need to perform an action on the first valid unit in a group. For more complex operations involving multiple units, consider using iteration methods.