Iterative function is returning an unexpected symbol

Luigifan18

Member
Hey, I tried to make an iterative function to enable Flora's Holy Flame to bust walls, and it's generating an error. Here's my code and the error.

Holy Flame Wall Smashing:
--Breaking bustable walls and spikes
addHook("MobjLineCollide", function(mobj, line)
    local backfront = {line.frontsector, line.backsector}
    
for rover in backfront.ffloors{
    if (mobj.z <= ffloor.topheight or mobj.z >= ffloor.bottomheight) then
        if ffloor.master.special == 252
        or ffloor.master.special == 253
        or ffloor.master.special == 254
        or ffloor.master.special == 255
        or ffloor.master.special == 256 then
            EV_CrumbleChain(backfront, rover) --Holy Flame can break bustable walls
            return true
        else
            continue
        end
    end}
end, MT_HOLYFLAMECORE)

addHook("MobjLineCollide", function(mobj, line)
    local backfront = {line.frontsector, line.backsector}
    
for rover in backfront.ffloors{
    if (mobj.z <= ffloor.topheight or mobj.z >= ffloor.bottomheight) then
        if ffloor.master.special == 252
        or ffloor.master.special == 253
        or ffloor.master.special == 254
        or ffloor.master.special == 255
        or ffloor.master.special == 256 then
            EV_CrumbleChain(backfront, rover) --Holy Flame can break bustable walls
            return true
        else
            continue
        end
    end}
end, MT_HOLYFLAME)

The first highlighted line is line 216 in my full Lua script, which is what's causing the error report:

It'd be nice if you told me [B]WHAT[/B] symbol was unexpected...:
WARNING: ...\SLADE\The Belnades Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:216: unexpected symbol near 'if'

So... what's the problem here? I'm not seeing it... help, please?
 

Attachments

  • LUA_FLORAABILITIES.txt
    61.9 KB · Views: 60
I reconfigured the iterative function to add some missing keywords, and it's not returning an error on load now, but it is returning an error when Holy Flame is used during gameplay. Here's the new code:

Holy Flame Wall Smashing:
--Breaking bustable walls and spikes
addHook("MobjLineCollide", function(mobj, line)
    local backfront = {line.frontsector, line.backsector}
   
    for rover in backfront.ffloors.iterate() do
        if (mobj.z <= ffloor.topheight or mobj.z >= ffloor.bottomheight) then
            if ffloor.master.line.special == 252
            or ffloor.master.line.special == 253
            or ffloor.master.line.special == 254
            or ffloor.master.line.special == 255
            or ffloor.master.line.special == 256 then
                EV_CrumbleChain(backfront, rover) --Holy Flame can break bustable walls
                return true
            else
                return
            end
        else
            continue
        end
    end
end, MT_HOLYFLAMECORE)

addHook("MobjLineCollide", function(mobj, line)
    local backfront = {line.frontsector, line.backsector}
   
    for rover in backfront.ffloors.iterate() do
        if (mobj.z <= ffloor.topheight or mobj.z >= ffloor.bottomheight) then
            if ffloor.master.line.special == 252
            or ffloor.master.line.special == 253
            or ffloor.master.line.special == 254
            or ffloor.master.line.special == 255
            or ffloor.master.line.special == 256 then
                EV_CrumbleChain(backfront, rover) --Holy Flame can break bustable walls
                return true
            else
                return
            end
        else
            continue
        end
    end
end, MT_HOLYFLAME)

The highlighted lines are where the new error is generated (with the first highlighted line being line 215 and the second highlighted line being line 236):

What's an ffloor?:
WARNING: ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:215: attempt to index field 'ffloors' (a nil value)
stack traceback:
    ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:215: in function <...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:212>

WARNING: ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:236: attempt to index field 'ffloors' (a nil value)
stack traceback:
    ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:236: in function <...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:233>
 

Attachments

  • LUA_FLORAABILITIES.txt
    62 KB · Views: 65
  • log-2023-08-11_13-51-37.txt
    21.3 KB · Views: 66
Last edited:
backfront is a table, and that table doesn't have the ffloors property, only its entries do. You need to iterate over the elements in the backfront table, THEN iterate over that table entry's ffloors. That should resolve your error!

I will also warn you that the else return will cause the loop to end early, so if it doesn't find it as the first collided FOF, it won't break anything. You would want to else continue there as well.
 
backfront is a table, and that table doesn't have the ffloors property, only its entries do. You need to iterate over the elements in the backfront table, THEN iterate over that table entry's ffloors. That should resolve your error!

I will also warn you that the else return will cause the loop to end early, so if it doesn't find it as the first collided FOF, it won't break anything. You would want to else continue there as well.
So… you're saying I need an iterator inside my iterator?
 

Attachments

  • CL_Flora-Belnades.pk3
    1.8 MB · Views: 85
  • Flora - Holy Flame v1.4.txt
    5.8 KB · Views: 67
  • LUA_FLORAABILITIES.txt
    64.3 KB · Views: 69
Hey, uh, I don't think that solved the problem...

Error:
WARNING: ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:188: bad argument #2 to '?' (invalid option 'ffloor')
stack traceback:
    [C]: ?
    ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:188: in function <...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:183>
WARNING: ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:211: bad argument #2 to '?' (invalid option 'ffloor')
stack traceback:
    [C]: ?
    ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:211: in function <...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:206>

Holy Flame Wall Smashing:
--Breaking bustable walls and spikes
addHook("MobjLineCollide", function(mobj, line)
    local backfront = {line.frontsector, line.backsector}
    
    for i, sector in ipairs(backfront) do
        for rover in sector.ffloors() do
            if (mobj.z <= sector.ffloor.topheight or (mobj.z + mobj.height) >= sector.ffloor.bottomheight) then --height check
                if sector.ffloor.master.line.special == 252
                or sector.ffloor.master.line.special == 253
                or sector.ffloor.master.line.special == 254
                or sector.ffloor.master.line.special == 255
                or sector.ffloor.master.line.special == 256 then
                    EV_CrumbleChain(backfront, rover) --Holy Flame can break bustable walls
                    return true
                else
                    continue
                end
            else
                continue
            end
        end
    end
end, MT_HOLYFLAMECORE)

addHook("MobjLineCollide", function(mobj, line)
    local backfront = {line.frontsector, line.backsector}
    
    for i, sector in ipairs(backfront) do
        for rover in sector.ffloors() do
            if (mobj.z <= sector.ffloor.topheight or (mobj.z + mobj.height) >= sector.ffloor.bottomheight) then --height check
                if sector.ffloor.master.line.special == 252
                or sector.ffloor.master.line.special == 253
                or sector.ffloor.master.line.special == 254
                or sector.ffloor.master.line.special == 255
                or sector.ffloor.master.line.special == 256 then
                    EV_CrumbleChain(backfront, rover) --Holy Flame can break bustable walls
                    return true
                else
                    continue
                end
            else
                continue
            end
        end
    end
end, MT_HOLYFLAME)
 

Attachments

  • CL_Flora-Belnades.pk3
    1.8 MB · Views: 70
  • Flora - Holy Flame v1.6.txt
    6 KB · Views: 62
  • log-2023-08-26_19-39-10.txt
    8.5 KB · Views: 69
I apologise for not responding, I've been quite busy.

Error:
WARNING: ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:188: bad argument #2 to '?' (invalid option 'ffloor')
stack traceback:
    [C]: ?
    ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:188: in function <...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:183>
WARNING: ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:211: bad argument #2 to '?' (invalid option 'ffloor')
stack traceback:
    [C]: ?
    ...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:211: in function <...Sisters\CL_Flora-Belnades.pk3|Lua/LUA_FLORAABILITIES:206>

See "invalid option"? This is telling you that "ffloor" is not a property of the sector. The "rover" you're iterating through is the replacement for it.

Code:
for i, sector in ipairs(backfront) do
        for rover in sector.ffloors() do
            if (mobj.z <= sector.ffloor.topheight or (mobj.z + mobj.height) >= sector.ffloor.bottomheight) then --height check
                if sector.ffloor.master.line.special == 252

So in this instance, you would replace all instances of "sector.ffloor" with "rover" - as it holds the FOF you're looking for.

Code:
                    EV_CrumbleChain(backfront, rover) --Holy Flame can break bustable walls

In addition, "backfront" should be replaced with "sector", as that's the actual sector to be using.

Let me know if this doesn't solve your issues!
 
Yep, I got those same suggestions on Discord, and they fixed the problem. I am currently having the problem of the FOF continuously crumbling until Holy Flame fades, but I have other things to fix.
 
Ah! Apologies for the delay, but glad you had it mostly sorted.

I know exactly what that last issue is - check for (ffloor.flags & FF_EXISTS) == FF_EXISTS - that should check whether it's been busted or not. :D
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top