• 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

Replicating conditions in LUA

AmericanNero

Seasoned veteran member
Joined
Oct 13, 2020
RedCents
4,709¢
Using JIT conditional evaluation is highly convenient in Macros, but, how do we do it in Lua?

The MacroQuest INI command supports noparse. Fortunately we don't need to specify that when loading INI anymore. There is a simple load/save lib which will read the contents into a table, where you can then make edits, then save. Back to evaluating conditions.

Here is what I've cooked up. Any suggestions appreciated.

JavaScript:
--[[
    Read the contents of an INI into a table, ex reference: pc.ACond.Cond1
    [ACond]
    ; Cond takes a LUA expression
    ; Cond1 returns false. Cond2 returns true.
    Cond1=mq.TLO.Me.Name ~= mq.TLO.Me.Name
    Cond2=mq.TLO.Me.Name == mq.TLO.Me.Name
--]]

local function Eval_Cond(cond)
    result=false
    local test_cond = load('result=' .. cond)
    test_cond()
    return result
end

local Cond1="mq.TLO.Me.Name ~= mq.TLO.Me.Name"
local Cond2="mq.TLO.Me.Name == mq.TLO.Me.Name"
print (Eval_Cond(Cond1))
print (Eval_Cond(Cond2))
 
you could just do this. forget INI.

Code:
local function Cond1()
    return mq.TLO.Me.Name() ~= mq.TLO.Me.Name()
end

local function Cond2()
    return mq.TLO.Me.Name() == mq.TLO.Me.Name()
end

print(Cond1())
print(Cond2())

Note that in your example you're comparing userdata which always would be not equal.
 
I did test the code before posting. It returns true and false, rather than TRUE FALSE, so the boolean works.

There's appeal to INI in that one can open it up simply in Notepad++ and tinker with it. Replicating the Cond functionality was a goal of mine.

Using LIP I can read it into a table structure, edit it however I like, and save it back to INI. Love it.
 
You can open a Lua file in an editor just the same. Use a Lua require as your condition file. Or a Lua table. Abandon INI it is terrible.
Also use vscode :)
 
I did test the code before posting. It returns true and false, rather than TRUE FALSE, so the boolean works.
A Boolean expression wouldn’t ever return TRUE or FALSE

forgot that I added a operator== for testing but I don’t know if it works outside of contrived examples such as this. It’s untested and undocumented
 
I don't understand what you are conveying. It seems counter to everything I've seen and done, and reported here. Shall I try replicate all my work from yesterday to show you what I saw?
 
Replicating conditions in LUA

Users who are viewing this thread

Back
Top
Cart