• 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 crash comparing with nil

Soandso2

Well-known member
Joined
Mar 13, 2023
RedCents
937¢
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.

[CODE lang="Lua" highlight="23"]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[/CODE]
 
if me.ActiveDisc() ~= nil and me.ActiveDisc.Name() ~= defensive then I'd try that.

ActiveDisc() itself will return a disc name if active.
 
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