• Hail, we're RedGuides. We want you to play six (yes, 6!) EverQuest characters at once. We have scripts and a friendly community to help, please join our playstyle and say hello! 👋
  • We've added LLM sections to our Terms & Rules and Resource Rules, for everyone's sanity & in-game safety.
    Read more
    a. Do not replace your voice with an LLM. This goes for your posts and your scripts. Drafting and editing with a tool is fine, but don't take you out of what you share.
    b. Do not replace your EQ character's voice with an LLM. We don't want scripts that speak over /ooc, /shout or other public channels. This has been an unwritten rule that's kept casino scripts off the site for decades, but we're now compelled to make it clear: keep automated communication private.

    Why Does RG Review Scripts?
    Nearly every LLM-written Lua script we see is making your character do impossible things, and rarely in a way that's beneficial to you. We've seen heavy server hammering, /target over impossible distances when /nav spawn would passively accomplish the same thing, a spawn search that fires 20+ times per second, and other pointless actions that are likely annoying GMs.

    You are welcome to use LLMs as a tool to structure, draft, and edit your work, but please read critically before hitting /lua run

Question - Lua crash comparing with nil

Soandso2

Well-known member
Yet another brainfart that I cannot figure out. I cant see what is wrong. It is straight forward as nothing else, but still it elludes me. Perhaps it is too early in the morning, i dont know. Any insights?

I get an error whenever this kicks in. Compare to/with nil on line 23.

Lua:
mq = require('mq')

require("utils")

local repDeath = spell("Defy Death").RankName()
local defensive = spell("Earthforce Discipline").RankName()

while true do
    if me.PctHPs() < 30 then
        if utils.goodToGo() and me.AltAbilityReady("Armor of Experience")() then
            mq.cmd("/alt act 2000")
            printf("[%s] \atRapids:: Armor of Experience",os.date('%H:%M:%S'))
        end
        if utils.goodToGo() and me.AbilityReady("Mend")() then
            mq.cmd("/doability mend")
            printf("[%s] \atRapids:: Mend",os.date('%H:%M:%S'))
        end
        if utils.goodToGo() and me.CombatAbilityReady(repDeath)() then
            mq.cmdf('/doability "%s"',repDeath)
            printf("[%s] \atRapids:: %s",os.date('%H:%M:%S'),repDeath)
        end
        if utils.goodToGo() and me.CombatAbilityReady(defensive)() then
            if me.ActiveDisc.ID() > 0 and me.ActiveDisc.Name() ~= defensive then
                mq.cmd("/stopdisc")
            end
            mq.cmdf('/doability "%s"',defensive)
            printf("[%s] \atRapids:: %s",os.date('%H:%M:%S'),defensive)
            mq.delay(500)
        end
    end
end
 
if me.ActiveDisc() ~= nil and me.ActiveDisc.Name() ~= defensive then I'd try that.

ActiveDisc() itself will return a disc name if active.
So, like this then:
Lua:
if me.ActiveDisc() ~= defensive then
    mq.cmd("/stopdisc")
end

I see, it is activedisc on mq.TLO.Me, not on mq.TLO.Spell in this case.
 
Probably need to check if it's not nil first or you'll get a nil crash when there isn't one.

Lua:
if me.ActiveDisc() ~= nil and me.ActiveDisc.BaseName() ~= defensive then
    mq.cmd("/stopdisc")
end

is probably how I'd handle it if you don't have the nil check when it checks for an ActiveDisc it's gonna return nil and not be comparable to your defensive and crash. BaseName instead of name keeps you from running into problems anywhere theres a Rk. 1, 2, 3 etc. May or may not be appropriate in your case. Saves you from having to worry about rank names in a lot of cases. I believe when you use a disc it defaults to the highest rank, as it removes lower ranks from your disc window.
 
So, like this then:
Lua:
if me.ActiveDisc() ~= defensive then
    mq.cmd("/stopdisc")
end

I see, it is activedisc on mq.TLO.Me, not on mq.TLO.Spell in this case.
This works fine. The reason your were getting an error before was not that ActiveDisc() was returning a nil, but that you were trying to compare a nil with number.
Lua:
if me.ActiveDisc.ID() > 0

In your latest changes, the check
Lua:
nil ~= "Some String Value"
does NOT throw an error and the nil check is unnecessary.
 
This works fine. The reason your were getting an error before was not that ActiveDisc() was returning a nil, but that you were trying to compare a nil with number.
Lua:
if me.ActiveDisc.ID() > 0

In your latest changes, the check
Lua:
nil ~= "Some String Value"
does NOT throw an error and the nil check is unnecessary.
Good to know. I wasn't sure and wasn't where I could test so I figured better to have the extra check than send someone off possibly with a new crash.
 
Question - Lua crash comparing with nil

Users who are viewing this thread

Back
Top
Cart