Changing state's var2 with Lua

Goldenhog

Wandering Protagonist
Code:
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo)
			if (player.mo.state == S_PLAY_WAIT)
				player.mo.state.var2 = 1
			end
		end
	end
end)
This is what I have so far. In theory, what this should do is: When the player enters their waiting animation state, var2 should be set to 1, which should make the animation play at really high speed due that state's use of FF_ANIMATE. Instead I get a "attempt to index field 'state' (a number value)" warning and the animation plays normally.
 
States in Lua are constants, meaning they are really just numbers (hence your console warning), and thus don't have a var2 field. They can be used as indices in the states table, which does contain state userdata with var2 fields that you can modify. This will affect every player in the S_PLAY_WAIT state, however.
Code:
states[S_PLAY_WAIT].var2 = 1    -- not in an addHook function
If you only want to affect the duration of S_PLAY_WAIT for a specific skin or player, you should set up a custom state instead.

TBH, I'm not entirely sure why SPR2-using states use FF_ANIMATE at all, given that they are capable of changing the displayed frame by transitioning into the same state. If they were set up like that instead you could change its duration per-player by manually setting player.mo.tics. Maybe it's MD2 related?
 
FF_ANIMATE support was coded in because of Super Sonic. I didn't want to have a special standing state just for the spine animations done for FSonic and FFSonic, since it was important that the nextstate of S_PLAY_STND be S_PLAY_WAIT. To that end, I added the FF_ANIMATE thing so that same-anim frame incrementing could be done without commandeering nextstate.

Also on the topic itself: You can modify mobj.anim_duration directly, you know that right? Modifying state stuff isn't net-safe, but anim_duration is.
 
I did try anim_duration but at the time of writing the OP it wasn't working for me either. I chalked it up to the docco not being totally correct since the page is still in progress of being updated.

Anyhow, I'm using custom states now and it's working. Thanks for the help!
 

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

Back
Top