Midair Dash LUA Fix Needed

I've tried giving a shot at making a multiple-use midair dash ability for an SRB2 character I'm making, but the script wouldn't work, even with the methods I've tried.

The LUA I've made in question:

//Hammer Leap

addHook("AbilitySpecial", function(player)
if player.mo.skin == "foof"
if player.pflags&PF_THOKKED
return false
end
local actionspd = FixedMul(player.mo.scale*12)
if player.mo.eflags & MFE_UNDERWATER
actionspeed = $/3
end
P_Instathrust(player.mo, player.mo.angle, actionspeed*2)
P_SetObjectMomZ(player.mo*10/FRACUNIT, true)
end
end)

When the addon is loaded, this warning appears on the console:

WARNING: ...rcade/SRB2 v2.2/addons/Characters/CL_Foof_Test.pk3|Lua/FoofAbilities.lua:13: ')' expected near '10'

If anyone has a solution to fixing up the code to make it work, it would be greatly appreciated.
 
I know nothing about Lua, but I think that means the '/' after 10 should be a ')'.
That's all I can really say and get from that warning, and I'm fully aware it's probably not gonna help. I tried-
 
Please indent your code.

Ability fix:
//Hammer Leap

addHook("AbilitySpecial", function(player)
    if player.mo.skin == "foof"
        if player.pflags & PF_THOKKED
            return false
        end
        local actionspeed = FixedMul(player.mo.scale, 12*FRACUNIT)
        if player.mo.eflags & MFE_UNDERWATER
            actionspeed = $/3
        end
        P_InstaThrust(player.mo, player.mo.angle, actionspeed*2)
        P_SetObjectMomZ(player.mo, 10*FRACUNIT, true)
    end
end)

P_SetObjectMomZ takes three arguments, so if you want to add 10*FRACUNIT to the player's current momz, you'd do it like above instead.

For future reference, arguments when calling a function are separated by commas. The wiki describes P_SetObjectMomZ as:
P_SetObjectMomZ(mobj_t mobj, fixed_t momz, [boolean relative?])
Where "player.mo" is your mobj, "10*FRACUNIT" is the fixed momz value, and "true" means it's a relative addition instead of directly setting momz to 10*FRACUNIT.

Additionally, the way you used FixedMul is incorrect, it requires two arguments that are numbers that are large enough to have "FRACUNIT" in their values. Of course, you can also just write "player.mo.scale * 12" without any FixedMul function, I just wanted to demonstrate how it would have worked.

Also P_InstaThrust had a typo in it, but I don't know if Lua calls are case-insensitive.

ALSO, you wrote actionspd but then decided to call it actionspeed, which is incorrect. Variable names should stay consistent.
 
Please indent your code.

Ability fix:
//Hammer Leap

addHook("AbilitySpecial", function(player)
    if player.mo.skin == "foof"
        if player.pflags & PF_THOKKED
            return false
        end
        local actionspeed = FixedMul(player.mo.scale, 12*FRACUNIT)
        if player.mo.eflags & MFE_UNDERWATER
            actionspeed = $/3
        end
        P_InstaThrust(player.mo, player.mo.angle, actionspeed*2)
        P_SetObjectMomZ(player.mo, 10*FRACUNIT, true)
    end
end)

P_SetObjectMomZ takes three arguments, so if you want to add 10*FRACUNIT to the player's current momz, you'd do it like above instead.

For future reference, arguments when calling a function are separated by commas. The wiki describes P_SetObjectMomZ as:
P_SetObjectMomZ(mobj_t mobj, fixed_t momz, [boolean relative?])
Where "player.mo" is your mobj, "10*FRACUNIT" is the fixed momz value, and "true" means it's a relative addition instead of directly setting momz to 10*FRACUNIT.

Additionally, the way you used FixedMul is incorrect, it requires two arguments that are numbers that are large enough to have "FRACUNIT" in their values. Of course, you can also just write "player.mo.scale * 12" without any FixedMul function, I just wanted to demonstrate how it would have worked.

Also P_InstaThrust had a typo in it, but I don't know if Lua calls are case-insensitive.

ALSO, you wrote actionspd but then decided to call it actionspeed, which is incorrect. Variable names should stay consistent.
Thanks for helping out! I'm a complete stranger to LUA so help like this is what I greatly appreciate.
 
This is entirely beside the point, but Lua isn’t an acronym like WAD is. It’s just the Portuguese word for the moon.
 

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

Back
Top