Confused Near the End of ThinkFrame Hook

Status
Not open for further replies.
I'm having trouble with my lua script in choalover_server_mod.wad. Here is the following warning I'm getting: WARNING: choalover_server_mod.wad|LUA_CHAO:129: unexpected symbol near ')'.

Code:
addHook("ThinkFrame", do
	for player in players.iterate
	
	if not (player.mo and mapheaderinfo[gamemap].rpgmode)
		continue
	end
	
	if (player.pflags & PF_NIGHTSMODE or player.spectator) continue end
	
	if (player.cmd.buttons & BT_CUSTOM1)
		if player.rpgaction == nil
			player.rpgaction = 4
		else if player.rpgaction == 4
			player.rpgaction = 3
		else if player.rpgaction == 3
			player.rpgaction = 2
		else if player.rpgaction == 2
			player.rpgaction = 1
		else if player.rpgaction == 1
			player.rpgaction = 0
		else if player.rpgaction == 0
			player.rpgaction = nil
		else
			player.rpgaction = nil
		end
	end
	
	if (player.cmd.buttons & BT_CUSTOM2) return end
	
	if (player.cmd.buttons & BT_CUSTOM3)
		if player.rpgaction == nil
			player.rpgaction = 0
		else if player.rpgaction == 0
			player.rpgaction = 1
		else if player.rpgaction == 1
			player.rpgaction = 2
		else if player.rpgaction == 2
			player.rpgaction = 3
		else if player.rpgaction == 3
			player.rpgaction = 4
		else if player.rpgaction == 4
			player.rpgaction = nil
		else
			player.rpgaction = nil
		end
	end
	
	end
end)
 
Lua uses "elseif", not "else if". Try changing those and see if that fixes your problem.
Thank you! This fixed my problem I was having. I just need to figure out how to fix a bug in my lua script.

EDIT: How do I make it where the code is only executed if the BT_CUSTOM1 is pressed and not held?
 
Last edited:
Store the previous state of player.cmd.buttons as another player struct variable, like player.mo.prevbuttons - and then update prevbuttons at the end of every thinkframe pass.

You can then update the button check section to check that not only are you currently pressing custom 1, but that you ALSO weren't pressing custom 1 in prevbuttons.

I'll leave the specific implementation to you, but this should likely work out.
 
Store the previous state of player.cmd.buttons as another player struct variable, like player.mo.prevbuttons - and then update prevbuttons at the end of every thinkframe pass.

You can then update the button check section to check that not only are you currently pressing custom 1, but that you ALSO weren't pressing custom 1 in prevbuttons.

I'll leave the specific implementation to you, but this should likely work out.
Thanks! I'll use this in custom 1 and 3. I'm going to put custom 2 in the player.mo.holdbuttons. By the way, player.rpgaction is a custom player struct variable.
 
Status
Not open for further replies.

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

Back
Top