Another Lua Problem

Status
Not open for further replies.
Code:
local PlayerHeight = player.mo.z
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo.skin = "yoshi" & player.powers[pw_super] & PF_JUMPED & (player.cmd.buttons & BT_USE) then
			player.mo.z = PlayerHeight
		else
		end
	end
end)

When I add the script, I get this in the console:

WARNING: Yoshi.wad|LUA_FLOT:6: unexpected symbol near '='

What am I doing wrong?
 
The problem is with this line:

if player.mo.skin = "yoshi" & player.powers[pw_super] & PF_JUMPED & (player.cmd.buttons & BT_USE) then

Here's where you're going wrong:
  • = is for assignment (changing the value of something), not for checking if x is equal to y. "==" is what you want to use instead for that, so to check that player.mo.skin is set to "yoshi", you use "player.mo.skin == "yoshi"" instead.
  • & isn't the symbol for logical and (that is, when you want to say two or more things should be true at the same time), you're meant to use "and" for that. "player.cmd.buttons & BT_USE" using & is fine, since there we're checking that BT_USE flag is set in player.cmd.buttons.
  • "PF_JUMPED" is meaningless on its own there, use "player.pflags & PF_JUMPED" to show you're checking if the flag is set in player.pflags. Just to be safe though, put brackets around that too.

The correct version should be:

if player.mo.skin == "yoshi" and player.powers[pw_super] and (player.pflags & PF_JUMPED) and (player.cmd.buttons & BT_USE) then

For your convenience, I bolded all the new and changed parts (it doesn't show for == though for some reason?).
 
Status
Not open for further replies.

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

Back
Top