• Hail, we're RedGuides. We want you to play six (yes, 6!) EverQuest characters at once. We have scripts and a friendly community to help, please join our playstyle and say hello! 👋
  • We've added LLM sections to our Terms & Rules and Resource Rules, for everyone's sanity & in-game safety.
    Read more
    a. Do not replace your voice with an LLM. This goes for your posts and your scripts. Drafting and editing with a tool is fine, but don't take you out of what you share.
    b. Do not replace your EQ character's voice with an LLM. We don't want scripts that speak over /ooc, /shout or other public channels. This has been an unwritten rule that's kept casino scripts off the site for decades, but we're now compelled to make it clear: keep automated communication private.

    Why Does RG Review Scripts?
    Nearly every LLM-written Lua script we see is making your character do impossible things, and rarely in a way that's beneficial to you. We've seen heavy server hammering, /target over impossible distances when /nav spawn would passively accomplish the same thing, a spawn search that fires 20+ times per second, and other pointless actions that are likely annoying GMs.

    You are welcome to use LLMs as a tool to structure, draft, and edit your work, but please read critically before hitting /lua run

Lua - LUA, TLOs, and final Parens

ButtKoWitz

Member
New to Lua and MQ so be patient :)...

I'm a little confused about when to include, or not, the final parenthesis when building an mq.TLO... call. The Lua Scripting in MacroQuest guide offers some info towards this, and definitely says "append () to the end to finally bring the result into lua"
(specifically here: https://docs.macroquest.org/lua/#tlo-bindings ). But where I'm confusing myself is when I'm looking over the example Lua scripts I see sometimes the mq.TLO... calls have extra ending parens, and sometimes not (most times not).

Two example scripts that come with default install of MQ) that have me confused are:
PackageMan.Lua ...
Line 28
Code:
local cliInstallPath = mq.TLO.Lua.Dir('modules')() .. '\\luarocks'
Are the final parens necessary, as ...Dir('modules') seems to me to be the closing set.

The other confusing call is:
autoassist.Lua
Line 5
Code:
local groupAssist = function () return mq.TLO.Me.GroupAssistTarget end -- Note the lack of parentheses here
Umm o.k. But why am I'm noting the "lack of parens here"?

Thanks!
 
so the ending parens turns the Lua userdata into the datatype you would expect, like a string, or int, or bool. so when you need those things youd want to use parens, or else its gonna be a Lua userdata, which you cant really do anything with as such.

the 2nd example dont have it, because its a condition, so the type it returns is not important, either you have a groupassist or you dont.

thats atleast how i understand it, i am most likely 149% wrong
 
so the ending parens turns the lua userdata into the datatype you would expect, like a string, or int, or bool. so when you need those things youd want to use parens, or else its gonna be a lua userdata, which you cant really do anything with as such.

the 2nd example dont have it, because its a condition, so the type it returns is not important, either you have a groupassist or you dont.

thats atleast how i understand it, i am most likely 149% wrong

In the second case, you want the object, no the value, so that you can pull other values from it later, I presume. Hard to tell from just that one line. Context is important.
 
if you want a Lua data type, you need trailing empty parens.
if you leave them off you get userdata which you can continue to use later

Code:
local groupAssist = function () return mq.TLO.Me.GroupAssistTarget end -- Note the lack of parentheses here

print(groupAssist.ID())

..
or just
Code:
local groupAssist = mq.TLO.Me.GroupAssistTarget
print(groupAssist.ID())
 
if you want a lua data type, you need trailing empty parens.
if you leave them off you get userdata which you can continue to use later

Code:
local groupAssist = function () return mq.TLO.Me.GroupAssistTarget end -- Note the lack of parentheses here

print(groupAssist.ID())

..
or just
Code:
local groupAssist = mq.TLO.Me.GroupAssistTarget
print(groupAssist.ID())
hmm what is the purpose of running a function there? would it return false if there was no groupassist set?
 
Lua - LUA, TLOs, and final Parens

Users who are viewing this thread

Back
Top
Cart