• 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 - Interpreting NULL value from MQ in Lua

tervalas

Active member
Joined
Oct 26, 2023
RedCents
386¢
Having an issue with a loop.

X going from 1 to 500. mq.TLO.Me.Book(x) is reading correct data as long as there is a legitimate value and all other comparisons (including mq.TLO.Me.Book(x) ~= nil) using it in an if statement work. The moment it gets to the point where Me.Book[x] would return NULL in MQ, it is still passing that nil test and then throwing an error for trying to use it later in the conditional.

Should I be checking for something other than nil? I've tried mq.TLO.Me.Book(x) ~= "NULL" too and it still passes.
 
() are your friend. Always remember ().
Everything you want evaluated to a Lua primitive should end in ().
() with a value in them like Me.Book(1) do not count. This still needs to end in () or it will just be userdata.

/Lua parse mq.TLO.Me.Book(1)()

Also check out Lua expression evaluator

1707630720090.png
 
As aquietone said, doing it without the () is using it as userdata rather than a different data type that can be evaluated. Adding those should return strings that you can evaluate against.
 
() are your friend. Always remember ().
Everything you want evaluated to a lua primitive should end in ().
() with a value in them like Me.Book(1) do not count. This still needs to end in () or it will just be userdata.

/lua parse mq.TLO.Me.Book(1)()

Also check out lua expression evaluator

View attachment 57318
I think I found what my main confusion was. Not just the fact that I knew about this and had already started doing it last time I was working on what I'm working on and just completely forgot as I was working on a different portion. But that the part I'm working on seemed to be working fine other than this exact problem. Realized after this post that this was because when I was assigning this value to a global, and then using it later on for debugging, that string.format is okay with userdata as an input to %s while I figured that was showing it was already a string value.
 
I think I found what my main confusion was. Not just the fact that I knew about this and had already started doing it last time I was working on what I'm working on and just completely forgot as I was working on a different portion. But that the part I'm working on seemed to be working fine other than this exact problem. Realized after this post that this was because when I was assigning this value to a global, and then using it later on for debugging, that string.format is okay with userdata as an input to %s while I figured that was showing it was already a string value.
I know what you mean about using variables out of scope as I was running into the same problem on a different Lua I was writing. Glad you got it working.

Oh, and to help keep your code legible, you don't need string.format() to pass information using %s or %d, simply used printf() or mq.cmdf(). These handle the formatting for you, so that:

[CODE lang="Lua" title="Autoformat"]-- Instead of having to use:
print('string.format('This is my %s', message))

-- You can use:
printf('This is my %s', message)[/CODE]
 
Oh, and to help keep your code legible, you don't need string.format() to pass information using %s or %d, simply used printf() or mq.cmdf(). These handle the formatting for you, so that:
I'm using the Write library functions (believe those are from Knightly but I may be wrong), and was just following from a different Lua for use. No biggy. This is more for me to see about making sure I'm understanding how to reinterpret macro code with Lua. I like tinkering, as I rarely have time to tackle a whole new thing.
 
Question - Interpreting NULL value from MQ in Lua

Users who are viewing this thread

Back
Top
Cart