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]
| Key | Default | Meaning |
|---|---|---|
life | 1000 | Maximum and starting life |
power | 3000 | Maximum power (1000 per level) |
attack | 100 | Attack strength in percent |
defence | 100 | Defence in percent (higher takes less damage) |
fall.defence_up | 50 | Extra defence in percent while falling |
liedown.time | 60 | Ticks spent lying down after a fall |
airjuggle | 15 | Juggle points: how much air combo damage the player can take |
sparkno | 2 | Default hit spark (fightfx action) |
guard.sparkno | 40 | Default guard spark |
ko.echo | 0 | Echo the KO voice |
volume | 0 | Volume offset for the character’s sounds |
intpersistindex | 60 | var slots from this index on survive between rounds |
floatpersistindex | 40 | The same for fvar |
[Size]
| Key | Default | Meaning |
|---|---|---|
xscale, yscale | 1, 1 | Draw scale of the sprites |
ground.back, ground.front | 15, 16 | Width behind / in front of the axis on the ground (push and screen edges) |
air.back, air.front | 12, 12 | The same in the air |
height | 60 | Height used when players jump over each other |
attack.dist | 160 | Default guard.dist of HitDefs |
proj.attack.dist | 90 | Default guard distance of projectiles |
proj.doscale | 0 | Scale projectiles with xscale / yscale |
head.pos | 0, 0 | Head position (used by some effects and BindToTarget) |
mid.pos | 0, 0 | Body centre |
shadowoffset | 0 | Vertical shadow offset |
draw.offset | 0, 0 | Draw offset of the sprites |
[Velocity]
Pairs are x, y. x is relative to facing.
| Key | Default |
|---|---|
walk.fwd, walk.back | 2.4, -2.2 |
run.fwd | 4.6, 0 |
run.back | -4.5, -3.8 |
jump.neu | 0, -8.4 |
jump.back, jump.fwd | -2.55, 2.5 |
runjump.back | -2.55, -8.1 |
runjump.fwd | 4, -8.1 |
airjump.neu | 0, -8.1 |
airjump.back, airjump.fwd | -2.55, 2.5 |
air.gethit.groundrecover | -0.15, -3.5 |
air.gethit.airrecover.mul | 0.5, 0.2 |
air.gethit.airrecover.add | 0, -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]
| Key | Default | Meaning |
|---|---|---|
airjump.num | 1 | Air jumps allowed |
airjump.height | 35 | Minimum height before an air jump |
yaccel | 0.44 | Gravity |
stand.friction | 0.85 | Ground velocity multiplier per tick while standing |
crouch.friction | 0.82 | The same while crouching |
stand.friction.threshold | 2 | Below this speed a standing player stops |
crouch.friction.threshold | 0.05 | The same while crouching |
air.gethit.groundlevel | 25 | Height at which a falling player counts as landed |
air.gethit.groundrecover.ground.threshold | -20 | Height below which a ground recovery is possible |
air.gethit.groundrecover.groundlevel | 10 | Landing height after a ground recovery |
air.gethit.airrecover.threshold | -1 | y velocity needed for an air recovery |
air.gethit.airrecover.yaccel | 0.35 | Gravity during an air recovery |
air.gethit.trip.groundlevel | 15 | Landing height after a trip |
down.bounce.offset | 0, 20 | Offset when a fallen player bounces |
down.bounce.yaccel | 0.4 | Gravity of the bounce |
down.bounce.groundlevel | 12 | Landing height of the bounce |
down.friction.threshold | 0.05 | Speed 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
| Key | Values | Default | Meaning |
|---|---|---|---|
type | S C A L U | S | State type: standing, crouching, air, lying down, unchanged |
movetype | I A H U | I | Idle, attacking, being hit, unchanged |
physics | S C A N U | N | Stand friction, crouch friction, air (gravity, lands at y = 0), none, unchanged |
anim | int | unchanged | Animation to start |
velset | x, y | unchanged | Velocity on entry |
ctrl | 0 / 1 | unchanged | Control on entry |
poweradd | int | 0 | Power added on entry |
juggle | int | 0 | Juggle points an air attack from this state costs |
facep2 | 0 / 1 | 0 | Turn to face the opponent on entry |
hitdefpersist | 0 / 1 | 0 | Keep the active HitDef from the previous state |
movehitpersist | 0 / 1 | 0 | Keep MoveHit / MoveContact information |
hitcountpersist | 0 / 1 | 0 | Keep the hit counter |
sprpriority | int | unchanged | Drawing 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
triggerallis true and at least one numbered group is true (all lines with the same number). Groups must be numberedtrigger1,trigger2, … without gaps; after a gap, later groups are ignored with a warning.trigger1is required (except forNull). persistent.1(default) fires every tick the triggers are true.0fires only once per state entry.nfires once every n ticks. In negative states it has no effect.ignorehitpause. During hit pause, controllers are skipped unless this is1.- Order. Controllers run top to bottom. A
ChangeStateruns 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 / 2is3(integer division);7 / 2.0is3.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:
| Precedence | Operators | Notes |
|---|---|---|
| 1 | ! ~ - + (unary) | logical not, bitwise not, negation |
| 2 | ** | power; groups left to right in rugen |
| 3 | * / % | |
| 4 | + - | |
| 5 | < <= > >= | |
| 6 | = != and ranges | x = [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
| Redirect | Points to |
|---|---|
parent | The helper’s parent |
root | The 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) |
partner | Your 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
| State | Runs | Typical use |
|---|---|---|
[Statedef -3] | every tick, before -2, except while you are in an opponent’s custom state | Effects that must run whatever you are doing |
[Statedef -2] | every tick, even in custom states | Global logic, timers |
[Statedef -1] | every tick, only in your own states | Move 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.
| Number | State |
|---|---|
| 0 | Stand |
| 10, 11, 12 | Stand to crouch, crouch, crouch to stand |
| 20 | Walk |
| 40, 45, 50, 52 | Jump start, air jump start, in the air, landing |
| 100, 105, 106 | Run forward, hop back, hop back landing |
| 120 .. 155 | Guard start, guarding (130 stand, 131 crouch, 132 air), guard end (140), guard hit (150 .. 155) |
| 170, 175 | Lose by time over, draw game |
| 180 .. 189 | Win poses (your own) |
| 190, 191 | Intro (your own) |
| 5000 .. 5099 | Hit reactions: standing, crouching, in the air, falling, trip |
| 5100, 5101 | Hit the floor, bounce |
| 5110, 5120 | Lying down, getting up |
| 5150 | Lying dead (KO) |
| 5200, 5210 | Fall recovery near the ground, recovery in the air |
| 5900 | Round 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
Projectilecontroller with the HitDef parameters plus speed, animation and removal rules. It has no states of its own. Track it withNumProjID,ProjHitTimeand friends. - A helper is a full extra player that runs your state code from the
statenoyou give it. It can attack, use projectiles, spawn other helpers and talk to its parent withParentVarSetand theparent,redirection. Remove it withDestroySelf.
[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.