• 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 - Coding Question: mq.TLO.Me.Class.ShortName

Joined
Oct 1, 2023
RedCents
927¢
Don't beat me up too badly please. Hacking my way through this stuff with no programming background. I'm not sure if there's an easy solution to this and my search skills are lacking or....

In macroscript you could write: /if (${Me.Class.ShortName.Equal[CLR,SHM,DRU]}) /dostuff

I'm struggling to figure out similar syntax in Lua.

The only options I've found through searching is creating an "am I a priest" function and calling the function when needed, or adding priest shortnames to a table and iterating through it. Is there an easier way to compare to one or more strings without a lengthy or list, a function, or iterating through a table?
 
Don't beat me up too badly please. Hacking my way through this stuff with no programming background. I'm not sure if there's an easy solution to this and my search skills are lacking or....

In macroscript you could write: /if (${Me.Class.ShortName.Equal[CLR,SHM,DRU]}) /dostuff

I'm struggling to figure out similar syntax in lua.

The only options I've found through searching is creating an "am I a priest" function and calling the function when needed, or adding priest shortnames to a table and iterating through it. Is there an easier way to compare to one or more strings without a lengthy or list, a function, or iterating through a table?
here's a snippet:
local my_class = mq.TLO.Me.Class.ShortName()

here's another:
mq.TLO.Me.Class.ShortName() ~= 'MAG' then

I got both of these from a text file search for "ShortName". In a text editor (I think Word has this function also), do a "Find in Files", using the "search subdirectories" option, pointing the search at your version of the MacroQuest\Lua folder.

There is gold in them thar hills.
 
You can use string.find(haystack, needle) to see if your text exists within another text.

For example:
[CODE lang="Lua" title="string.find"]_CasterClasses = 'DRU,CLR,SHM,MAG,WIZ,NEC,ENC'

if string.find(_CasterClasses, mq.TLO.Me.Class.ShortName()) then
mq.cmd("/echo match")
else
mq.cmd("/echo no match")
end[/CODE]

string.find will return nil if the value is not found. It will return the position of the value if it is found.
nil resolves as False. The first position is 1, which resolves to true.

Alternatively, for your specific use case, you can use:

[CODE title="HealerType"]mq.TLO.Me.Class.HealerType()[/CODE]

This returns a boolean
1720185918568.png
 
You can use string.find(haystack, needle) to see if your text exists within another text.

For example:
[CODE lang="lua" title="string.find"]_CasterClasses = 'DRU,CLR,SHM,MAG,WIZ,NEC,ENC'

if string.find(_CasterClasses, mq.TLO.Me.Class.ShortName()) then
mq.cmd("/echo match")
else
mq.cmd("/echo no match")
end[/CODE]

string.find will return nil if the value is not found. It will return the position of the value if it is found.
nil resolves as False. The first position is 1, which resolves to true.

Alternatively, for your specific use case, you can use:

[CODE title="HealerType"]mq.TLO.Me.Class.HealerType()[/CODE]

This returns a boolean
View attachment 63022
That's perfect, thank you!
 
To compare to a list of classes you can create a table where the classes are the key and the value are just true. Then just check to see if the class is in the table.
 
To compare to a list of classes you can create a table where the classes are the key and the value are just true. Then just check to see if the class is in the table.
Is there a cleaner way to do this than iterating through the table with a for loop?
 
Is there a cleaner way to do this than iterating through the table with a for loop?
Lua:
local healers = {CLR = true, DRU = true, SHM = true}
if healers[mq.TLO.Me.Class.ShortName()]  ~= nil then
--- we matched
end
no loop needed. which is why Brainiac said use key's as the names its an easy match.
 
Lua:
local healers = {CLR = true, DRU = true, SHM = true}
if healers[mq.TLO.Me.Class.ShortName()]  ~= nil then
--- we matched
end
no loop needed. which is why Brainiac said use key's as the names its an easy match.
Awesome! I couldn’t wrap my head around the syntax. Thank you! Now I’m following.
 
Question - Coding Question: mq.TLO.Me.Class.ShortName

Users who are viewing this thread

Back
Top
Cart