What does 'end' expected (to close 'if' at line 4) near '<eof>' mean and how do I fix it?

Julia

The only SRB2 and Touhou fan ever to exist lmao
So I'm helping @jimbojimbob with his mod, and I'm making him a flight cancel. Problem is, the code spats out the error 'end' expected (to close 'if' at line 4) near '<eof>' when loaded in. For reference, here's the code so you can see what I'm working with:
Flight Cancel script.:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo and player.mo.skin == "tails" then
            if (player.cmd.buttons & BT_CUSTOM1)
            and player.panim == PA_ABILITY
            and not P_IsObjectOnGround(player.mo)
                player.pflags = $1 & PF_JUMPED
                player.mo.state = S_PLAY_JUMP

        if player.mo and player.mo.skin == "tails" then
            if player.pflags & PF_JUMPED
                player.pflags = $1 & PF_JUMPED
                player.mo.state = S_PLAY_JUMP

        if player.mo and player.mo.skin == "tails" then
            if player.pflags & PF_SHIELDABILITY
                player.pflags = $1 & PF_SHIELDABILITY
                player.mo.state = S_PLAY_FALL
            end
        end
    end
end

So can any lua experts help me out here?
Post automatically merged:

NOTICE: The top piece of code works fine on its own. I just need to fix 2 oversights that causes tails to not hurt badniks when using said move.
 
You need to add ends to close off all ifs unless it's closed by an else or elseif.
Fixed Code:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo and player.mo.skin == "tails" then
            if (player.cmd.buttons & BT_CUSTOM1)
            and player.panim == PA_ABILITY
            and not P_IsObjectOnGround(player.mo)
                player.pflags = $1 & PF_JUMPED
                player.mo.state = S_PLAY_JUMP
            end
        end
        
        if player.mo and player.mo.skin == "tails" then
            if player.pflags & PF_JUMPED
                player.pflags = $1 & PF_JUMPED
                player.mo.state = S_PLAY_JUMP
            end
        end
        
        if player.mo and player.mo.skin == "tails" then
            if player.pflags & PF_SHIELDABILITY
                player.pflags = $1 & PF_SHIELDABILITY
                player.mo.state = S_PLAY_FALL
            end
        end
    end
end

Also, this really could be a PlayerThink.
 
Not only are you missing several "end"s, you're also missing the closing parentheses at the end, which is why it spits out that error. Here's a fixed version of the code, which shouldn't print errors to the console:

Lua:
addHook("ThinkFrame", do
    for player in players.iterate
        if player.mo and player.mo.skin == "tails" then
            if (player.cmd.buttons & BT_CUSTOM1)
            and player.panim == PA_ABILITY
            and not P_IsObjectOnGround(player.mo)
                player.pflags = $1 & PF_JUMPED
                player.mo.state = S_PLAY_JUMP

        if player.mo and player.mo.skin == "tails" then
            if player.pflags & PF_JUMPED
                player.pflags = $1 & PF_JUMPED
                player.mo.state = S_PLAY_JUMP
            end
        end

        if player.mo and player.mo.skin == "tails" then
            if player.pflags & PF_SHIELDABILITY
                player.pflags = $1 & PF_SHIELDABILITY
                player.mo.state = S_PLAY_FALL
            end
        end
    end
end)
 

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

Back
Top