YesNoOk
avatar

Not understanding how state controllers are updated during run movement (Read 2133 times)

Started by FluffyQuack, May 31, 2024, 11:15:34 pm
Share this topic:
Not understanding how state controllers are updated during run movement
#1  May 31, 2024, 11:15:34 pm
  • avatar
This example is taken from a King character from KOF Anthology. Maybe this is a normal way of handling running -- I haven't checked. Anyway, running and stopping the run works fine, but I don't understand why.

This is the relevant code:
Code:
;-----RUN
[Statedef 100]
type = S
movetype = I
physics = S
anim = 100
velset = 0
ctrl = 0

[State 100, 1]
type = ChangeState
trigger1 = AnimTime = 0
value = 101

[Statedef 101]
type = S
movetype = I
physics = S
anim = 101
ctrl = 0

[State 100, 1]
type = VelSet
trigger1 = 1
x = const(velocity.run.fwd.x)

[State 100, 0]
type = PlaySnd
trigger1 = AnimElem = 1
value = 0,3
loop = 1
channel = 1

[State 101, 3]
type = ChangeState
trigger1 = command = "holdup"
value = 40

[State 100, 5.1]
type = ChangeState
triggerall = var(9) = 0
trigger1 = AnimElem = 3, >= 0
trigger1 = command != "holdfwd"
value = 102

[State 100, 5.2]
type = ChangeState
trigger1 = var(9) = 1
trigger1 = AnimElem = 3, >= 0
trigger1 = P2bodydist X <= 40
value = 102

[Statedef 102]
type = S
movetype = I
physics = S
anim = 102

[State 102, 1]
type = ChangeState
trigger1 = AnimTime = 0
value = 0
ctrl = 1; RUN_BACK2 (land)

When starting to run, the game changes to state 100. A few ticks later, it changes to the 101 state, which is the actual running loop. However, there's only one state controller for state 101, which is for handling jumping. The state controller for ending the run is defined for state 100 (it changes to 102 when ending the run). Now then, letting go of forward works fine and the characters stops running, but why is this? Are the state controllers for 100 somehow being run for 101 too?
Re: Not understanding how state controllers are updated during run movement
#2  June 01, 2024, 12:03:22 am
  • avatar
I'm doing some tests and I think I've figured it out. Am I right when I say the written state id for a state controller is ignored? I think the game processes every state controller that succeeds a state definition until it encounters another state definition in the list.
Re: Not understanding how state controllers are updated during run movement
#3  June 01, 2024, 01:42:38 am
  • avatar
Okay, I'm now very certain that the written state controller IDs have zero effect and it's all about the order they're placed in the CNS file.

One thing I'm wondering now is how state overrides work. If I have state 100 in both commons1.cns and king.cns, which controllers will be run? The ones in common1.cns and king.cns, or only the ones in king.cns?
Re: Not understanding how state controllers are updated during run movement
#4  June 01, 2024, 02:06:29 am
  • ******
  • 90's Kawaii
  • :thinking:
    • Guatemala
Okay, I'm now very certain that the written state controller IDs have zero effect and it's all about the order they're placed in the CNS file.
That is correct. Their labeling is irrelevant, you can name every single block "[state 69, big whoop]" and it won't have any impact. Statedef 101 only ends when you define the next statedef header, not when you name a block "[state 102, whatever]". People frequently copy paste code from different states without bothering to change the numbers.

One thing I'm wondering now is how state overrides work. If I have state 100 in both commons1.cns and king.cns, which controllers will be run? The ones in common1.cns and king.cns, or only the ones in king.cns?
Character specific files take priority over the common files, so in your example the statedef 100 defined in king.cns overrides common1.cns
Re: Not understanding how state controllers are updated during run movement
#5  June 02, 2024, 01:31:49 am
  • avatar
Thanks for the clarification! I was a bit confused as I looked up guides and documentation, and some of them said that state controllers must have the same ID as the state they belong to.