RUGENDOCS
Creating content

CNS: constants, states, expressions

The .cns format - the constant sections, how a state is built from a [Statedef] and its controllers, trigger logic, the expression language with its operators and type rules, and the special and common states.

A .cns file holds two things: the character’s constants and its states. The .st files and common1.cns contain states only. The .cmd file uses the same state syntax for its [Statedef -1].

Constants

rugen reads four sections from the cns file. Every key is optional; a missing key takes the default below (defaults are for 320 x 240 and are scaled to your localcoord; values you write are used as written). Read them in states with Const(section.key), for example Const(velocity.walk.fwd.x).

[Data]

KeyDefaultMeaning
life1000Maximum and starting life
power3000Maximum power (1000 per level)
attack100Attack strength in percent
defence100Defence in percent (higher takes less damage)
fall.defence_up50Extra defence in percent while falling
liedown.time60Ticks spent lying down after a fall
airjuggle15Juggle points: how much air combo damage the player can take
sparkno2Default hit spark (fightfx action)
guard.sparkno40Default guard spark
ko.echo0Echo the KO voice
volume0Volume offset for the character’s sounds
intpersistindex60var slots from this index on survive between rounds
floatpersistindex40The same for fvar

[Size]

KeyDefaultMeaning
xscale, yscale1, 1Draw scale of the sprites
ground.back, ground.front15, 16Width behind / in front of the axis on the ground (push and screen edges)
air.back, air.front12, 12The same in the air
height60Height used when players jump over each other
attack.dist160Default guard.dist of HitDefs
proj.attack.dist90Default guard distance of projectiles
proj.doscale0Scale projectiles with xscale / yscale
head.pos0, 0Head position (used by some effects and BindToTarget)
mid.pos0, 0Body centre
shadowoffset0Vertical shadow offset
draw.offset0, 0Draw offset of the sprites

[Velocity]

Pairs are x, y. x is relative to facing.

KeyDefault
walk.fwd, walk.back2.4, -2.2
run.fwd4.6, 0
run.back-4.5, -3.8
jump.neu0, -8.4
jump.back, jump.fwd-2.55, 2.5
runjump.back-2.55, -8.1
runjump.fwd4, -8.1
airjump.neu0, -8.1
airjump.back, airjump.fwd-2.55, 2.5
air.gethit.groundrecover-0.15, -3.5
air.gethit.airrecover.mul0.5, 0.2
air.gethit.airrecover.add0, -4.5
air.gethit.airrecover.back / .fwd / .up / .down-1 / 0 / -2 / 1.5

Pair constants are read as Const(velocity.run.fwd.x) and .y. The jump y velocity is also available as Const(velocity.jump.y).

[Movement]

KeyDefaultMeaning
airjump.num1Air jumps allowed
airjump.height35Minimum height before an air jump
yaccel0.44Gravity
stand.friction0.85Ground velocity multiplier per tick while standing
crouch.friction0.82The same while crouching
stand.friction.threshold2Below this speed a standing player stops
crouch.friction.threshold0.05The same while crouching
air.gethit.groundlevel25Height at which a falling player counts as landed
air.gethit.groundrecover.ground.threshold-20Height below which a ground recovery is possible
air.gethit.groundrecover.groundlevel10Landing height after a ground recovery
air.gethit.airrecover.threshold-1y velocity needed for an air recovery
air.gethit.airrecover.yaccel0.35Gravity during an air recovery
air.gethit.trip.groundlevel15Landing height after a trip
down.bounce.offset0, 20Offset when a fallen player bounces
down.bounce.yaccel0.4Gravity of the bounce
down.bounce.groundlevel12Landing height of the bounce
down.friction.threshold0.05Speed below which a lying player stops sliding

[Quotes]

victory0 .. victory99 are victory quotes. rugen’s result screen shows one of them at random.

States

A state is one thing the character does: standing, a jab, a fireball, being thrown. It starts with a [Statedef] header followed by state controllers that run every tick while the player is in the state.

[Statedef 210]
type = S
movetype = A
physics = S
anim = 210
ctrl = 0
velset = 0, 0
poweradd = 30
juggle = 2

[State 210, hit]
type = HitDef
trigger1 = AnimElem = 3
attr = S, NA
damage = 40
animtype = Medium
guardflag = MA
pausetime = 12, 12
ground.velocity = -5

[State 210, end]
type = ChangeState
trigger1 = AnimTime = 0
value = 0
ctrl = 1

[Statedef] parameters

KeyValuesDefaultMeaning
typeS C A L USState type: standing, crouching, air, lying down, unchanged
movetypeI A H UIIdle, attacking, being hit, unchanged
physicsS C A N UNStand friction, crouch friction, air (gravity, lands at y = 0), none, unchanged
animintunchangedAnimation to start
velsetx, yunchangedVelocity on entry
ctrl0 / 1unchangedControl on entry
poweraddint0Power added on entry
juggleint0Juggle points an air attack from this state costs
facep20 / 10Turn to face the opponent on entry
hitdefpersist0 / 10Keep the active HitDef from the previous state
movehitpersist0 / 10Keep MoveHit / MoveContact information
hitcountpersist0 / 10Keep the hit counter
sprpriorityintunchangedDrawing layer

Only the first letter of type, movetype and physics counts. An unknown letter is an error and the state is skipped (rugen check shows it). If a key appears twice, the first one wins.

Controllers

Every controller has a header, a type and at least one trigger:

[State 210, label]        ; the label is free text, shown in errors
type = PlaySnd            ; which controller
triggerall = Time >= 0    ; optional, all must be true
trigger1 = Time = 2       ; trigger1 lines: all must be true...
trigger2 = MoveHit = 1    ; ...or all trigger2 lines, and so on
value = 0, 1              ; the controller's own parameters
persistent = 0            ; optional: how often it may fire
ignorehitpause = 1        ; optional: also run during hit pause
  • Trigger logic. The controller fires if every triggerall is true and at least one numbered group is true (all lines with the same number). Groups must be numbered trigger1, trigger2, … without gaps; after a gap, later groups are ignored with a warning. trigger1 is required (except for Null).
  • persistent. 1 (default) fires every tick the triggers are true. 0 fires only once per state entry. n fires once every n ticks. In negative states it has no effect.
  • ignorehitpause. During hit pause, controllers are skipped unless this is 1.
  • Order. Controllers run top to bottom. A ChangeState runs the new state at once; the rest of the old state is skipped.

See State controllers for every type.

Expressions

Triggers and most parameters are expressions. They mix numbers, triggers, operators and functions.

trigger1 = Command = "QCF_x" && Power >= 1000
trigger1 = P2BodyDist X < 30 && P2StateType != A
value = ifelse(Facing = 1, 1000, 1001)
x = Const(velocity.walk.fwd.x) * 1.5

Types

Values are int, float or bottom (no value).

  • An operation with any float operand is done in floating point.
  • 7 / 2 is 3 (integer division); 7 / 2.0 is 3.5.
  • % always works on ints.
  • Converting float to int truncates toward zero.
  • Integer overflow wraps.
  • Division or % by zero gives bottom, for floats too.
  • Bottom reads as 0 in arithmetic and comparisons and is false as a condition. You get it from errors (Ln(0)) and from redirections to players that do not exist.

Operators

From highest to lowest precedence:

PrecedenceOperatorsNotes
1! ~ - + (unary)logical not, bitwise not, negation
2**power; groups left to right in rugen
3* / %
4+ -
5< <= > >=
6= != and rangesx = [a, b]
7:=assignment, only to var(n) / fvar(n) / sysvar(n) / sysfvar(n)
8&bitwise and
9^bitwise xor
10|bitwise or
11&&logical and (short-circuit)
12^^logical xor
13||logical or (short-circuit)

Use parentheses whenever you are unsure. ** is a common trap: write 2 ** (3 ** 2) if you mean a right-grouped tower.

Ranges

After = or != you can compare against an interval. Square brackets include the end, round ones exclude it:

trigger1 = StateNo = [200, 299]      ; 200 to 299
trigger1 = Time = (0, 10]            ; 1 to 10
trigger1 = Anim != [5000, 5999]      ; anything outside

Assignment inside expressions

:= writes a variable and returns the value. Use it sparingly; it is mostly for counters in triggers:

trigger1 = (var(3) := var(3) + 1) > 10

Redirection

Prefix a trigger with a player to read that player instead of yourself:

trigger1 = parent, Life < 200
trigger1 = root, StateNo = 1000
trigger1 = helper(1201), NumExplod = 0
trigger1 = target, StateType = A
trigger1 = enemynear, Pos Y < -40
trigger1 = playerid(var(40)), Alive
RedirectPoints to
parentThe helper’s parent
rootThe main player at the top of the helper chain
helper / helper(id)Your first helper (with that id)
target / target(id)Your first target (hit by a HitDef with that id)
partnerYour team mate (none in rugen yet: always bottom)
enemy / enemy(n)The n-th opponent
enemynear / enemynear(n)The n-th closest opponent
playerid(id)The player or helper with that unique ID

If the player does not exist, the result is bottom. Math functions and some global triggers are not redirectable; the trigger reference says which.

Special states

StateRunsTypical use
[Statedef -3]every tick, before -2, except while you are in an opponent’s custom stateEffects that must run whatever you are doing
[Statedef -2]every tick, even in custom statesGlobal logic, timers
[Statedef -1]every tick, only in your own statesMove selection: the .cmd’s ChangeState list

Negative states always come from your own files. A ChangeState there stops the rest of that negative state for the tick.

Common states

common1.cns (from data/) provides the states every character needs. Override any of them by defining the same number in your own files.

NumberState
0Stand
10, 11, 12Stand to crouch, crouch, crouch to stand
20Walk
40, 45, 50, 52Jump start, air jump start, in the air, landing
100, 105, 106Run forward, hop back, hop back landing
120 .. 155Guard start, guarding (130 stand, 131 crouch, 132 air), guard end (140), guard hit (150 .. 155)
170, 175Lose by time over, draw game
180 .. 189Win poses (your own)
190, 191Intro (your own)
5000 .. 5099Hit reactions: standing, crouching, in the air, falling, trip
5100, 5101Hit the floor, bounce
5110, 5120Lying down, getting up
5150Lying dead (KO)
5200, 5210Fall recovery near the ground, recovery in the air
5900Round initialisation

rugen starts some basic actions itself from raw input, as MUGEN does: guard (120), jump (40), air jump (45), crouch (10), stand up (12), walk (20) and back to stand (0).

Helpers and projectiles

  • A projectile is a hit that flies: one Projectile controller with the HitDef parameters plus speed, animation and removal rules. It has no states of its own. Track it with NumProjID, ProjHitTime and friends.
  • A helper is a full extra player that runs your state code from the stateno you give it. It can attack, use projectiles, spawn other helpers and talk to its parent with ParentVarSet and the parent, redirection. Remove it with DestroySelf.
[State 1200, summon]
type = Helper
trigger1 = AnimElem = 3
id = 1201
stateno = 1250
pos = 40, -80

[Statedef 1250]
type = A
physics = N
anim = 1250
ctrl = 0

[State 1250, fly]
type = VelSet
trigger1 = Time = 0
x = 3

[State 1250, gone]
type = DestroySelf
trigger1 = Time > 120 || FrontEdgeDist < -40

Helpers do not read your commands unless spawned with keyctrl = 1, and they run [Statedef -1] only then. A normal helper skips states -2 and -3; a helpertype = player helper runs them.

Original reference: elecbyte.com/mugendocs-11b1.

Something wrong on this page? Edit it on GitHub.

SEARCH !!

    ↑↓ to move, Enter to open