I need help with this lua..

Status
Not open for further replies.

SlasherTH

Member
Hello, SlasherTH here. Can I please get help with this Shadow wad I'm porting to 2.1?? I wanted skating sounds when walking and running, I got running, but I can't get walking. When I load up the lua for the skating sounds when walking on SRB2 it says this:


WARNING: shadow2.1.wad|LUA_WALK:45: unexpected symbol near ')'

Here's the lua, where did I mess up?


addHook("ThinkFrame", do
if (player.mo and player.mo.skin == "shadow")
and (player.panim == PA_WALK)
and player.mo and player.mo.valid and player.health
and not (player.powers[pw_super])


if mo and P_IsObjectOnGround(mo) then


if (mo.state==S_PLAY_RUN3) or (mo.state==S_PLAY_SPD4)

S_StartSound(mo, sfx_skate1)

end
end

if (mo.state==S_PLAY_RUN7) or (mo.state==S_PLAY_SPD2)

S_StartSound(mo, sfx_skate2)

end
end
end
end
end
end)
 
Code:
addHook("ThinkFrame", do
        if ([B]player.mo[/B] and [B]player.mo[/B].skin == "shadow") // In a ThinkFrame hook, players and mobjs aren't automatically found for you. The type of hook should be changed, or you should use iterators to find them.
	and ([B]player[/B].panim == PA_WALK)
	and [B]player.mo[/B] and [B]player.mo[/B].valid and [B]player[/B].health
	and not ([B]player[/B].powers[pw_super])
		if [B]mo[/B] and P_IsObjectOnGround([B]mo[/B]) then // Switched from using "player.mo" to just "mo". You use one or the other depending on if you searched for players or mobjs.
			if ([B]mo[/B].state == S_PLAY_RUN3) or ([B]mo[/B].state == S_PLAY_SPD4)
				S_StartSound([B]mo[/B], sfx_skate1)
			[B]end[/B] // Only one "end" is needed to close an "if" statement; using more messes up how the script is read by the game
			end
			if ([B]mo[/B].state == S_PLAY_RUN7) or ([B]mo[/B].state == S_PLAY_SPD2)
				S_StartSound([B]mo[/B], sfx_skate2)
			[B]end[/B]
			[B]end[/B]
			end
		end
	end
end)

Bolded the mistakes I found here, and added some comments. In addition to the extraneous end's MPC pointed out, you should also properly search for mobj/players. You can do that by either iterating through players with "for player in players.iterate do", or switch over to using a MobjThinker hook.

After that, you would need to replace instances of "mo" with "player.mo" or vice versa, depending on which method you used. (If you used a iterator, then you would replace mo with player.mo, but if you used a MobjThinker then you would replace player.mo with mo.) Here's how I would do it, if you can't figure it out yourself (if this doesn't work, bear with me I did this from memory without testing it):

Code:
addHook("MobjThinker", function(mo)
	if (mo and mo.valid and mo.player.health)
	and (mo.skin == "shadow")
	and (mo.player.panim == PA_WALK)
	and not (mo.player.powers[pw_super])
		if P_IsObjectOnGround(mo) then
			if (mo.state == S_PLAY_RUN3) or (mo.state == S_PLAY_SPD4)
				S_StartSound(mo, sfx_skate1)
			end
			if (mo.state == S_PLAY_RUN7) or (mo.state == S_PLAY_SPD2)
				S_StartSound(mo, sfx_skate2)
			end
		end
	end
end, MT_PLAYER)

Hope this helps!!
 
Last edited:
Status
Not open for further replies.

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

Back
Top