YesNoOk
avatar

States (CNS) (Read 2855 times)

Started by Just No Point, September 25, 2015, 08:43:06 pm
Share this topic:
States (CNS)
New #1  September 25, 2015, 08:43:06 pm
  • ******
    • www.justnopoint.com/
Animations and sounds are the most immediately noticeable manifestations of a MUGEN character, but the true "heart" of the character is its CNS file(s). The CNS file, also known as the character's "states" file, contains the code that actually gives the character its functionality -- allowing it to perform moves when commanded, to hit its opponent, or to obey the law of gravity.

The structure of a CNS file is simple. Code is organized into logical groups called [StateDef]s. [StateDef] blocks are numbered, and a typical character may contain hundreds of them. Within each [StateDef] is a number of [State] blocks, also known as state controllers. Each state controller is a trigger-action pair: it specifies some action for the character to take, and the conditions under which that action should be performed.

At each instant ("tick") of game time, the character executes the code in some [StateDef] block. For instance, if the character is standing idly, then it is typically executing in the [StateDef 0] block. For brevity, we say that the character is "in state 0". At each tick that the character is in state 0, it will evaluate the state controllers in the [StateDef 0] block from top to bottom, checking the conditions and taking any actions that are specified. If the character needs to change to some other [StateDef] block, let's say to state 417 because it is performing a move, it can execute a ChangeState state controller to make the switch. The character will then start executing the code in [StateDef 417], in exactly the same fashion.

Each MUGEN character additionally has three special states, numbered -1, -2, and -3. These are the only allowable states with negative numbers. State -1 generally contains state controllers that determine state transition rules based on user input (commands). State -2 contains other state controllers that need to be checked every tick. State -3 contains state controllers which are checked every tick unless the player is temporarily using another player's state data (for instance, when the player is being thrown).

To put it all together: for each tick of game-time, MUGEN makes a single pass through each of the special states, from top to bottom, in order of increasing state number (-3, -2, then -1). For each state controller encountered, its condition-type triggers are evaluated and, if they are satisfied, the controller is executed. Then processing proceeds to the next state controller in the state. A state transition (ChangeState) in any of the special states will update the player's current state number, and will abort processing the remainder of the state. After all the state controllers in the special states have been checked, the player's current state is processed, again from top to bottom. If a state transition is made out of the current state, the rest of the state controllers (if any) in the current state are skipped, and processing continues from the beginning of the new state. When the end of the current state is reached and no state transition is made, processing halts for this tick.

There is one exception to the above scenario. If the character is a "helper" character, i.e., spawned by the Helper state controller, that character will not have the special states -3 and -2. The helper character will not have the special state -1 either, unless it has keyboard input enabled. (This is controlled by the Helper state controller when the character is created.)

max stateno is 2147483647
Last Edit: December 10, 2016, 09:30:41 am by Odb718
Re: States
#2  September 29, 2015, 01:32:54 pm
  • **
    • Brazil
    • thundermugen.com/
Helpers does not use state -1 to -3 by default, but, if you put the trigger IsHelper in a controller in these states, they will be able to use that controller...
I've done that in the past to prevent some helpers from bugging and going to state 5000 after being hit (I don't remember it well, but there was a strange bug in the helper that caused it to go the char hit state some times), so, with that I could send the helpers back to their correct state.
Not sure if this still works on MUGEN 1.0 or 1.1...
Re: States
#3  September 29, 2015, 04:16:37 pm
  • *****
  • Gaps? Where we're going, we don't need gaps...
    • USA
    • ricepigeon.neocities.org
Helpers does not use state -1 to -3 by default, but, if you put the trigger IsHelper in a controller in these states, they will be able to use that controller...

This only applies to State -1, and only if keyctrl is enabled in the Helper SCTRL that creates it. Helpers never inherit State -2 or -3. If you were overriding the hit behavior of the helpers so that they don't go into the regular hitstates, you were most likely using a HitOverride SCTRL for that.
Last Edit: September 29, 2015, 04:20:34 pm by Ricepigeon
Re: States (CNS)
#4  October 01, 2015, 03:11:11 pm
  • **
    • Brazil
    • thundermugen.com/
Helpers does not use state -1 to -3 by default, but, if you put the trigger IsHelper in a controller in these states, they will be able to use that controller...

This only applies to State -1, and only if keyctrl is enabled in the Helper SCTRL that creates it. Helpers never inherit State -2 or -3. If you were overriding the hit behavior of the helpers so that they don't go into the regular hitstates, you were most likely using a HitOverride SCTRL for that.

When I did this, I think it was on WinMugen, long time ago... But I'm quite sure I used StateDef -2 with the trigger IsHelper, and the Helper could actually see that Sctrl and use it... I'll test this later on...
Re: States (CNS)
#5  October 02, 2015, 06:53:57 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
You can allow helpers to access state -2 and -3 however it is not recommended in any way whatsoever.

Helpertype = Player

This turns the helper into another instance of the player. The issue is p2 will autoturn to face the object if said object is closest, fine if it's a clone and hurting it actively hurts p1 as well. Terrible if it is a rock, or a lifebar or something. Only use this for bonus stages. Elecbyte don't recommend using it at all.

If the helper needs -2 or -3 functionality, have it pull from the player, or use state -1 with keyctrl = 1


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.