• 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 - LUA concatenating strings and integers

Rare Spawn

Well-known member
Joined
Oct 10, 2022
RedCents
3,282¢
I need a hint as to why this doesnt work like I think it should. The error I get is about about concatenating the string and the integer value of ID.
I read that Lua .. is suppose to convert to strings automatically. I attempted to use tostring() with no luck.

This throws a Lua error:
[CODE lang="Lua" title="Error"]mq.cmd("/mqtarget id "..mq.TLO.SpawnSort(1,asc,PctHPs,"xtarhater radius 90").ID())[/CODE]

And this is a workaround:
[CODE lang="Lua" title="Non Lua workaround"]mq.cmd("/mqtarget id ${SpawnSort[1,asc,PctHPs,xtarhater radius 90].ID}")[/CODE]

What is the correct way to do this is Lua?

Thanks.
 
I need a hint as to why this doesnt work like I think it should. The error I get is about about concatenating the string and the integer value of ID.
I read that LUA .. is suppose to convert to strings automatically. I attempted to use tostring() with no luck.

This throws a LUA error:
[CODE lang="lua" title="Error"]mq.cmd("/mqtarget id "..mq.TLO.SpawnSort(1,asc,PctHPs,"xtarhater radius 90").ID())[/CODE]

And this is a workaround:
[CODE lang="lua" title="Non LUA workaround"]mq.cmd("/mqtarget id ${SpawnSort[1,asc,PctHPs,xtarhater radius 90].ID}")[/CODE]

What is the correct way to do this is LUA?

Thanks.
[CODE lang="Lua"]
mq.cmdf("/mqtarget id %d",mq.TLO.SpawnSort(1,asc,PctHPs,"xtarhater radius 90").ID())
[/CODE]

Cannot answer your question about why it doesn't convert it automatically but here is how to use it.
 
I need a hint as to why this doesnt work like I think it should. The error I get is about about concatenating the string and the integer value of ID.
I read that LUA .. is suppose to convert to strings automatically. I attempted to use tostring() with no luck.

This throws a LUA error:
[CODE lang="lua" title="Error"]mq.cmd("/mqtarget id "..mq.TLO.SpawnSort(1,asc,PctHPs,"xtarhater radius 90").ID())[/CODE]

And this is a workaround:
[CODE lang="lua" title="Non LUA workaround"]mq.cmd("/mqtarget id ${SpawnSort[1,asc,PctHPs,xtarhater radius 90].ID}")[/CODE]

What is the correct way to do this is LUA?

Thanks.

Is SpawnSort a valid TLO? Don't see it on the docs and it seems to be not found trying it in the console.

You should use formatted strings with the mq.cmdf as jande mentioned.

maybe you want mq.TLO.Spawn or mq.TLO.NearestSpawn or mq.getFilteredSpawns instead

Lua:
local closest_pc_id = mq.TLO.NearestSpawn('1,pc radius 100').ID()
printf('Targeting the closest pc id=%s', closest_pc_id)
mq.cmdf('/mqt id %s', closest_pc_id)
 
MQ2SpawnSort is a real plugin, but you're correct that its not listed in the mq.definitions. But here it is https://www.redguides.com/docs/projects/mq2spawnsort/tlo-spawnsort/
ah never looked at that plugin before i guess.

Lua:
mq.cmdf("/mqtarget id %d", mq.TLO.SpawnSort('1,asc,PctHPs,xtarhater radius 90').ID())

in that case, for what jande posted, you'd also want the argument to spawnsort enclosed in quotes, the TLO input should be a single string.

Code:
> /echo ${SpawnSort[1,asc,PctHPs,"pc radius 90"]}
<myname>
> /lua parse mq.TLO.SpawnSort('1,asc,PctHPs,pc radius 90')
<myname>
 
Do what jande (for cmdf) and aquietone (for syntax) said, but the reason your first one doesn't work is because your syntax is wrong:
Lua:
mq.cmd("/mqtarget id "..mq.TLO.SpawnSort('1,asc,PctHPs,xtarhater radius 90').ID())

But that logic is also wrong, you should really check to make sure you have a spawn before trying to target it.
 
Lua:
local spawn = mq.TLO.SpawnSort('1,asc,PctHPs,xtarhater radius 90')
if spawn.ID() > 0 then spawn.DoTarget() end
 
Where can I see a list of all the
Lua:
local spawn = mq.TLO.SpawnSort('1,asc,PctHPs,xtarhater radius 90')
if spawn.ID() > 0 then spawn.DoTarget() end

Thats nice. I overlooked the actions section of spawn object. So if I stick the 'userdata' into a variable, instead of adding the extra () at the end to make it a string, I can treat the variable like an object instead of a string. 🤯
 
Question - LUA concatenating strings and integers

Users who are viewing this thread

Back
Top
Cart