• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Question - Concatenating mq.TLO string data?

Joined
Nov 2, 2022
RedCents
53¢
Hey, though I've programmed before, I'm super new to MQ and Lua. I'm trying to setup some mq.events depending on some variables, using mq.TLO.Target.Name to be precise. When I try to concatenate it with any string at all, like print(mq.TLO.Target.Name .. ' test'), the script crashes. I've been reading Lua documentations a bit, but I'm stumped here. I'm sure it's a simple problem/solution, but I'd appreciate someone pointing a newbie in the right direction.
 
Solution
there are several ways to concat with lua > here is the lua concat page <

you can do

Lua:
print('thing' .. var) - this would concat the value of "var" on the end of thing
you could also just do
Lua:
print('thing' .. 'stuff') -- this would concat "stuff" onto "thing" resulting in thingstuff

here is me running that in mq using the /lua parse functionality
Lua:
> /lua parse print('thing' .. 'stuff')
thingstuff

what you would likely be wanting to do is something like

Lua:
-- this is bringing in MQ "stuff"
local mq = require 'mq'

-- we are evaluating and assigning the information from our target's name to a variable named "targetname" - care to notice the "()" on the end of it, this means we want the data from it, not the...
there are several ways to concat with Lua > here is the lua concat page <

you can do

Lua:
print('thing' .. var) - this would concat the value of "var" on the end of thing
you could also just do
Lua:
print('thing' .. 'stuff') -- this would concat "stuff" onto "thing" resulting in thingstuff

here is me running that in mq using the /Lua parse functionality
Lua:
> /lua parse print('thing' .. 'stuff')
thingstuff

what you would likely be wanting to do is something like

Lua:
-- this is bringing in MQ "stuff"
local mq = require 'mq'

-- we are evaluating and assigning the information from our target's name to a variable named "targetname" - care to notice the "()" on the end of it, this means we want the data from it, not the actual datatype
local targetname = mq.TLO.Target.Name()

local function main()
    -- this is printing the aforcreated targetname and putting ' is gonna die' on the end of it
    -- if we were targeting RedBot (sorry red) it would print "RedBot is gonna die"
    print(targetname .. ' is gonna die')
end

-- this has the lua script run the function we created above
main()

here's another quick and dirty example of different ways to do something like that
Lua:
local mq = require 'mq'

local function main()
    local targetname = mq.TLO.Target.Name()
    local myname = mq.TLO.Me.Name()
    print(string.format("%s %s %s %s", "My Name: ", myname, " Target is: ", targetname))
end

main()

I had the note in the commends of the above Lua, but hytiek skipped over it later so i edited this to include "-- we are evaluating and assigning the information from our target's name to a variable named "targetname" - care to notice the "()" on the end of it, this means we want the data from it, not the actual datatype"

your snippet is missing the "()" on the end
 
Last edited:
Solution
there are several ways to concat with lua > here is the lua concat page <

you can do

Lua:
print('thing' .. var) - this would concat the value of "var" on the end of thing
you could also just do
Lua:
print('thing' .. 'stuff') -- this would concat "stuff" onto "thing" resulting in thingstuff

here is me running that in mq using the /lua parse functionality
Lua:
> /lua parse print('thing' .. 'stuff')
thingstuff

what you would likely be wanting to do is something like

Lua:
-- this is bringing in MQ "stuff"
local mq = require 'mq'

-- we are evaluating and assigning the information from our target's name to a variable named "targetname" - care to notice the "()" on the end of it, this means we want the data from it, not the actual datatype
local targetname = mq.TLO.Target.Name()

local function main()
    -- this is printing the aforcreated targetname and putting ' is gonna die' on the end of it
    -- if we were targeting RedBot (sorry red) it would print "RedBot is gonna die"
    print(targetname .. ' is gonna die')
end

-- this has the lua script run the function we created above
main()
Thanks for the swift reply! So, turns out the problem was with the way I was calling mq.TLO.Target.Name as I assumed it was a property, when I should have used () at the end like calling a function. Or is it still a property and that's just Lua syntax?
 
Thanks for the swift reply! So, turns out the problem was with the way I was calling mq.TLO.Target.Name as I assumed it was a property, when I should have used () at the end like calling a function. Or is it still a property and that's just Lua syntax?
good rule of thumb is "always use () if you want the information from the thing"

example:

in my guildclicky i use

Lua:
local ground = mq.TLO.Ground

this allows me later to do things like ground.Search (without typing the mq.TLO.Ground)

Lua:
local function validateportal(item)
    return ground.Search(item)() ~= nil
end
 
To address precisely what you shared:

print(mq.TLO.Target.Name .. ' test')

needs to be:

print(mq.TLO.Target.Name() .. ' test')

I recommend rather using:

print(mq.TLO.Target.CleanName() .. ' test')

Now when you get further and find an error about being unable to concatenate a Boolean:

print('printing my Boolean: '.. tostring(bVar1))
 
Question - Concatenating mq.TLO string data?

Users who are viewing this thread

Back
Top
Cart