Tutorial Part 1 - Getting started: sprites

Started by JustNoPoint, October 27, 2015, 04:36:57 PM

Previous topic - Next topic

JustNoPoint

How Do I...? A M.U.G.E.N primer

Tutorial Part 1 - Getting started: sprites

M.U.G.E.N, Elecbyte (c)1999-2009
Updated 17 September 2009


Tutorial 1 | 2 | 3 | 4

Introduction

If you want to make a character for M.U.G.E.N, you'll need a good understanding of how every component of a character works. Because jumping straight into the technical documentation can be confusing, we've written a tutorial to help you get started. As you gain more understanding, be sure to refer to the docs often. You may stumble or get stuck several times as you make your first character, but like anything else, once you know the basics it becomes easier and faster to make progress.



In this tutorial you will learn how to make a palette for your character, and how put together your character's sprites. Also, you'll see how to make a simple animation action. In Part 2 of the tutorial, you'll see how to define bounding boxes for your animations, and in Part 3 and 4 we'll define a simple attack. For this tutorial, you'll need an image editing program such as GIMP, PhotoShop, or PaintShop Pro.



We'll assume you have at least basic knowledge of text editors, graphics editing, game concepts, and how to navigate at a command prompt. If you're not familiar with all of these, we recommend you do some reading up in beginner books or websites. If you have some background in programming languages, you may find it a lot easier to understand our docs. All right, now let's begin.


1. Making a palette

All the sprites belonging to a character need to be 256-color PNG files. Every sprite should have the same 256-color palette in order for them to be displayed correctly in-game. If you are experienced with Photoshop, the following part will be simple. We will assume you are starting with a true-color image (called RGB in Photoshop).

When converting sprites to 256 colors (also known as Indexed Color), most paint programs will make the palette however which way they like, and they'll do it differently for each sprite. Here we'll cover how to make a standard palette, and how to apply it to each sprite..

With Photoshop, go to Image->Mode->Indexed Color.

A window will pop up. In this window, set the palette to Exact. If you're using Photoshop 5 or higher, don't click on OK yet. For earlier versions of Photoshop, click OK, then convert to RGB (Image->Mode->RGB Color), then click on Image->Mode->Indexed Color again.

Now, select Custom in the palette roll-down list to bring up the Color Table window. The next step is to make sure the background color of your sprite has a color index of 0 (we'll call this "color 0"). In M.U.G.E.N, color 0 is the masking color. This means that all the parts of a sprite that are color 0 will not be drawn.

Color index 0 should always be the background color. The actual color (not the index value) is up to you.

In Photoshop's color table editor, set the top left color (that's color index 0 in Photoshop) to be the background color of the sprite. You will want to make sure that color 0 is a unique color in your palette, otherwise Photoshop will not set the color indices correctly. To do this, you can take the old color 0 color and put it where the bg color used to be (swap the two colors essentially).

Note: If you have used versions of M.U.G.E.N prior to 1.0, the preferred file format used to be PCX instead of PNG. In Photoshop, PCX files have the bottom right color as index 0. With PNG files, it is the top left color.

Example of a correct palette with background color as color 0 (green in the top left corder).

Result of using incorrect palette. Result of using correct palette.

Click on the Save button to save this palette (we will call it player.act for the purpose of this tutorial). Now click OK to apply the palette to this image, and the save the file as a PNG file.

The next step is to convert all your other images to this palette that you just created (player.act). You can use the following method:

  • Open the first image, then click on Image -> Mode -> Indexed Color.
  • Select Custom from the Palette list, and click on Load to select the palette file you just made (player.act). Hit OK until you are back at the main window.
  • Now save it as a PNG file, and repeat for the rest of your images.

Palette design is very important early on when making your sprites. Although M.U.G.E.N lets you use up to 255 colors for each sprite, a character with a well-designed palette does not necessarily have to use all the available colors indices. Working with a limited number of colors not only decreases the size of the PNG files, but also makes it easier to create alternate palettes (different color schemes) later on. Pixel sprite art done by hand is easier with a small set of colors (16 to 32), but can become tedious when you have a large palette to work with. On the other hand, pre-rendered sprites may look better with a larger range of colors, at the cost of little extra work. Keep these points in mind when designing your character's palette.


2. How do I start making a character?

Go to the chars/ directory and make a new directory for your character. Let's call this character "Player", for an example (replace "player" with whatever you want to call your character). In this case, make a directory called chars/player.

3. What does this character need?

You'll need to have these in the chars/player directory:

player.air
player.cmd
player.cns
player.def
player.sff
player.snd
To see what each of these files are, read the Overview included in the docs/ directory of the M.U.G.E.N zip file.
In this tutorial, you'll make player.sff, the sprite file.

4. How do I start making these files?

You can make them all from scratch... Or, you can start by using our example character Kung Fu Man (KFM). KFM's character directory is located in chars/kfm/, and his work files are in work/kfm/.

5. OK, I got KFM. Now what?

The first thing to do is to copy over and rename the files needed for your character. Assuming your player's directory name is "player", these are the files you should copy:


chars/kfm/kfm.air -> chars/player/player.air
chars/kfm/kfm.cns -> chars/player/player.cns
chars/kfm/kfm.cmd -> chars/player/player.cmd
chars/kfm/kfm.def -> chars/player/player.def
What are these files? These 4 files are all in text format, which you can edit in a text editor such as MS-DOS EDIT or Windows WordPad. Here is a list of each of these files, what they do, and their corresponding technical documentation files.
  • .air - Animation data. This describes how your sprites will be animated. (AIR format)
  • .cns - Constants and states. This is where you define your character's state machine. It is the core of how a character behaves. (CNS format, Expressions)
  • .cmd - Move command definitions. The .cmd defines which input move commands trigger which attack states. It works with the .cns file to define how your character reacts to keyboard or joystick input. (The CMD file)
  • .def - Files and basic information about a character (The DEF file)



Spoiler: Original Tutorial Use this if you don't wish to use Fighter Factory and wish to use SPRMaker2 (click to show)
To set up your character's basic information, open player.def using a text editor. Change the fields to the appropriate values. For example:


; Player information
[Info]
name = "Player"             ;Name of character
displayname = "Player"      ;Name of character to display
versiondate = 09,09,2009    ;Version date of character (MM-DD-YYYY)
mugenversion = 1.0          ;Version of M.U.G.E.N character works on
author = "My Name"          ;Character author name
pal.defaults = 1,2,3,4      ;Default palettes in order of preference (up to 4)
                            ;Numbering starts from 1
localcoord = 320,240        ;Local coordinate space width and height

; Files for the player
[Files]
cmd     = player.cmd        ;Command set
cns     = player.cns        ;Constants
st      = player.cns        ;States
stcommon = common1.cns      ;Common states (from data/ or motif)
sprite  = player.sff        ;Sprite
anim    = player.air        ;Animation
sound   =                   ;Sound (leave blank if none) *** Set to blank for now ***
ai      = kfm.ai            ;AI hints data (not used)

; Arcade mode
[Arcade]
intro.storyboard =     ;*** Set to blank for now ***
ending.storyboard =    ;*** Set to blank for now ***

Making the sprite file

Now let's make player.sff, the character's sprite file. It will contain all the graphics used by your character. The sprite file is called an SFF, and the tool that generates it is called sprmake2 (short for Sprite Maker 2 -- it is a newer version of a tool used prior to M.U.G.E.N 1.0).

We'll concentrate on just making standing animation for now. If you already have the sprites you want to use, get those ready. Let's say that the standing animations you want to use are named stand00.png - stand03.png and are in the work/player/ directory. Now, make a text file inside work/player/ and call that file player-sff.def. Here's the start of the text file you would use (comment lines begin with a semicolon).



[Output]
 ;Filename of the SFF file to create (required).
filename = chars/player/player.sff

[Option]
 ;Leave all these options at default.  Don't worry about what they do for now.
sprite.compress.5 = lz5
sprite.compress.8 = rle8
sprite.compress.24 = none
sprite.decompressonload = 0
sprite.detectduplicates = 0
sprite.autocrop = 1
pal.detectduplicates = 1
pal.discardduplicates = 1
pal.reverseact = 0
pal.reversepng = 0

[Pal]
 ;This is where you specify color palettes that the character has.
 ;1,1 maps to color scheme 1; 1,2 to color scheme 2 and so on.
 ;You can have up to 6.
1,1, stand00.png

[Option]
 ;This option forces all sprites you add to use palette 1,1.
 ;It helps ensure your SFF file is built correctly.
sprite.usepal = 1,1

[Sprite]
 ;This is where you specify all your sprites.
 ;The first two numbers on each line are the group and image number.
 ;That is a pair of numbers you use to uniquely identify each sprite.
 ;The filename is specified next.
 ;Following that, the last two numbers are the X and Y axis.  You'll
 ;need to change the axis numbers for your own sprites.
0, 0, stand00.png,  18,105
0, 1, stand01.png,  18,104
0, 2, stand02.png,  18,104
0, 3, stand03.png,  18,104
; end of file

The group number and image number you enter for each sprite is used to access it in the .air (animation) file. It's just a pair of numbers you will associate with the sprite. For example, instead of referring to stand02.pcx, you will refer to 0,2.

Group number 0 is used for standing frames. You can check the AIR docs and Optional Animation Standards later for recommended numbers for other animation actions. The image number just specifies which image it is within a particular group number. You have to get your own X and Y axis from your sprite. For standing frames, it is usually at the very bottom in the middle of the sprite. For jumping sprites, the axis is usually in the where the character's feet would be if they were standing. That usually is in the center below the sprite. You can check KFM's sprites by running M.U.G.E.N and pressing Ctrl-C while playing. This will bring up the characters' bounding boxes and axes. Here are some examples of axis positions.

The positioning of your axes is very important. If they are slightly off between sprites, you will notice your sprites "jittering" around. If you make bigger errors, your sprites can end up appearing in completely wrong places.

Once you have player.txt ready, go to the directory where you have mugen.exe and sprmake2.exe, etc and make player.sff by typing at the command prompt:


  sprmake2 work\player\player-sff.def
If you get errors or player.sff wasn't made, check your player-sff.def file for mistakes.


Skip to step 6 to complete the old tutorial. When it asks you to use Fighter Factory you will instead use a text editor.

First you want to get Fighter Factory. You can find it here. Or use the Mirror here

Install Fighter Factory and run the program.
You should see the screen below (not including the character of course)


Let's break down what we will need for this tutorial. They are numbered on the image in red
1. Projects: You will use this to open or start new projects.
2. Definitions
3. Sprites: This is the current screen we have open in the example pic
4. Add one or more sprites
5. Load a new image for the sprite from a file
6. Save one or more sprites as image files
7. Save sprites: saves the sff
8. Duplicate the current sprite
9. Delete the current sprite
10. Delete a group of sprites
11. Find/replace text in a single line
12. Remove free borders from the sprite: Crop the image
13. Rename a group of sprites
14. Open the image editor
15. Scroll bar to scroll through sprites
16. Sprite Group Number
17. Sprite Index Number
18. axis
19. Decompress on load: pending details
20. Show transparency color: This will allow you to see the border of the sprites too
21. Switch to the sprite palette: pending details
22. OnionSkin: Use this to create a greyed duplicate sprite useful for aligning axis
23. OnionSkin scroll bar: Useful to scroll the sprites to be used for onionskin
24. Organizer: Use this to organize the order of the sprites and palettes

Fighter Factory can accept .pcx and .png file formats.

This tutorial will presume you are starting from scratch and have sprites available and ready.
To begin go to Projects > New to start a new character.
We will walk you through the various screens now.

For this example we will choose Empty. True type Fonts: Pending The only template that comes by default is Winane ai which is used to aid developers make ai for characters that use winmugen and should not be used with 1.0+


Should be self explanatory

Now that that is finished we can start.

To set up your character's basic information, open player.def using the Definitions tab. Change the fields to the appropriate values. For example:

; Player information
[Info]
name = "Player"             ;Name of character
displayname = "Player"      ;Name of character to display
versiondate = 09,09,2009    ;Version date of character (MM-DD-YYYY)
mugenversion = 1.0          ;Version of M.U.G.E.N character works on
author = "My Name"          ;Character author name
pal.defaults = 1,2,3,4      ;Default palettes in order of preference (up to 4)
                            ;Numbering starts from 1
localcoord = 320,240        ;Local coordinate space width and height

; Files for the player
[Files]
cmd     = player.cmd        ;Command set
cns     = player.cns        ;Constants
st      = player.cns        ;States
stcommon = common1.cns      ;Common states (from data/ or motif)
sprite  = player.sff        ;Sprite
anim    = player.air        ;Animation
sound   =                   ;Sound (leave blank if none) *** Set to blank for now ***
ai      = kfm.ai            ;AI hints data (not used)

; Arcade mode
[Arcade]
intro.storyboard =     ;*** Set to blank for now ***
ending.storyboard =    ;*** Set to blank for now ***


Now we can open the Sprites tab and begin adding sprites. The 1st thing you will see is


In the above image you see how you will apply the axis, name the group and index, and apply the palette.
You are also asked if you wish to crop the image. This will crop after the axis is applied. Before release be sure all sprites are cropped to lower the size of the sff.

The group number and image number you enter for each sprite is used to access it in the .air (animation) file. It's just a pair of numbers you will associate with the sprite.


The palette bares some explanation.
The Reversed Check Box will flip your palette. In most cases this is needed if you are saving with PhotoShop.

Image's palette if not already added: If you have no sprites you will want to start with this. Or if you are adding new sprites that have their own palette.

Force the specified palette (adapt the image): This will force your current palette onto the sprite and change colors that are nearest to the values in the palette;

Exchange with the specified palette: This allows you to apply the palette of the group/index sprite listed below. This is what you will most likely use once you have added the character sprites and wish to add more.

Group number 0 is used for standing frames. You can check the AIR docs and Optional Animation Standards later for recommended numbers for other animation actions. The image number just specifies which image it is within a particular group number. You have to get your own X and Y axis from your sprite. For standing frames, it is usually at the very bottom in the middle of the sprite. For jumping sprites, the axis is usually in the where the character's feet would be if they were standing. That usually is in the center below the sprite. You can check KFM's sprites by running M.U.G.E.N and pressing Ctrl-C while playing. This will bring up the characters' bounding boxes and axes. Here are some examples of axis positions.

The positioning of your axes is very important. If they are slightly off between sprites, you will notice your sprites "jittering" around. If you make bigger errors, your sprites can end up appearing in completely wrong places.

And that's pretty much it. Repeat for each new sprite(s).

Be sure to save often. When it is time to save you will see the following.


Choose yes. At this point most document readers can read UTF-8


This is where you will choose which MUGEN version/sff format you wish to use for your sff.

MUGEN Beta is WinMugen. It uses SFFv1 which is not able to use remappal.

1.0 allows you to use multiple palettes within the sff and remappal

1.1 allows you to use multiple palettes within the sff and remappal and 32bit images that can have more than 256 colors.

6. I made the SFF. What's next?

Okay, now that you have the standing sprites in player.sff, it's time to animate your character. To make the standing animation, you have to create an action for it (an action is a block of text that describes one sequence of sprites to display). Open up player.air in the animations tab, and let's get ready to add a standing animation action. If your player.air is a copy of kfm.air, you can simply edit the appropriate action group (action 0 for standing animation).



It's time to make player.air. If you've read the AIR docs, you'll know the format for .air is:


Group number, image number, X offset, Y offset, game-ticks, [options]
Don't worry about the lines that start with Clsn2 and Clsn2Default for now.


; Standing Animation
[Begin Action 0]   ;Action 0 is the standing animation
Clsn2Default: 2
 Clsn2[0] = -10,  0, 10,-79
 Clsn2[1] =  -4,-92,  6,-79
0,3, 0,0, 7  
;The above line means to use sprite (0,3) (ie. group 0, image number 3) and 
;display it for 7 game-ticks.  1 game-tick is 1/60 of a sec, so 60 
;ticks is 1 second.  Group 0 Image 3 is stand03.pcx.
0,2, 0,0, 7
0,1, 0,0, 7
0,0, 0,0, 7
0,1, 0,0, 7
0,2, 0,0, 7
;end of file

Now, save this file and you're ready to see how your character looks!


7. Checking out your actions

If all the files are in the right place, you can directly load your character with M.U.G.E.N by typing at the command prompt:


mugen player player

This is a shortcut for versus mode. For now, don't worry if you see warnings at the top of the screen. Warnings are a sign that there's something wrong or missing in your character. In this case, your character might be missing required sprites or animation actions.

If you find a sprite too high up, as if it is floating above the ground, you'll have to move the axis higher up. Just remember that the axis is on ground-level when the character is on the ground. Likewise, if your character is too far forwards, move the axis right. Once you've adjusted the axes for all the sprites correctly, your character shouldn't be sliding or fidgeting around during the animation.

If you accidentally entered a sprite group+image number that doesn't exist, then nothing will be drawn. So if you see your character blinking out, you should go back and check your .air file to see if the numbers correspond to the ones in used for building your .sff.


8. Continuing with Actions and Sprites

After making the standing frames, you can proceed to walking, then jumping. Now that you know the basics of making sprites and actions, you should continue by making the required sprites from The Sprite Standard and required actions from the Reserved Action Numbers in the AIR docs. When you're done, all the warnings at the top of the screen should go away.




In part 2 of the tutorial, you'll be able to define your character's bounding boxes so they can get hit and hit other characters. Finally, we'll show you how to define some attacks in the .cns.

Tutorial 1 | 2 | 3 | 4

Next is Tutorial Part 2






Feel free to post links to your favorite tutorials in this thread as well as discuss the content

JustNoPoint

The link to exp.html for the expressions documentation is dead.

Is this somewhere else? Any info on this missing doc?

JustNoPoint

Updated the sff tutorial to use Fighter Factory

Can someone explain the following a bit for me?
What exactly is Decompress on load for?
Switch to the sprite palette?

When opening a character I presume Tru Type Font template would be used to load true type fonts for a fnt file?

Odb718

Switch to the Sprite Palette does that on the sprite index change.
Meaning if you're on say sprite 1920 of 2300, and you finally get out of your character and into the Effects.
The effects will probably use their own palettes. If Switch is activated FF3 automatically views the sprite in it's main palette.
If it's not checked, it'll use palette 1,0 or what ever palette the previous palette was.

This works well if you're in your character and un-check Switch to the Sprite and on an alt-palette. You can kinda see how ALL of your sprites will look with the second set of colors. If it IS checked and you switch to palette 1,1 and move down the list to the next sprite, it'll jump back to palette 1,0 showing you the default colors.
vVv Gouken718 vVv SabreTooth718 vVv


JustNoPoint


Cyanide

#5
exp.html has no links or anything in it. As they didn't include it, it has not changed from the winmugen days and it's relatively short.

Spoiler (click to show)
Expressions
===========
M.U.G.E.N, (c) Elecbyte 2002
Documentation for version 2002.04.14

Beta-release documentation
Updated 27 October 2001



====================================================================
0. Contents
====================================================================

MUGEN supports the use of arithmetic expressions in the CNS and CMD files. This document gives a complete description of
expression syntax.

I.    Data types: Ints and Floats
II.   Arithmetic operators
III.  Precedence and associativity of operators
IV.   Expression syntax
V.    Triggers
VI.   Trigger redirection
VII.  SC values
VIII. More on function-type triggers
IX.   Expressions in state and state controller parameters
X.    (Advanced) Optimizing for speed



====================================================================
I. Data types: Ints and Floats
====================================================================

An int is a whole number, such as 0, 1, -4, etc. Ints can assume values
between about -2 billion and 2 billion. A float is a real number which
has a "decimal part", such as 5.24, or -4247.44. Note that a whole number such as 55 can also be represented as a float, thus: 55.0. Floats offer only 7 significant figures of precision.

The behavior of arithmetic expressions depends heavily on the underlying data types used to represent numbers. Also, state controllers may expect their input to be given as a certain type, and will give errors if the wrong type is supplied.



====================================================================
II. Arithmetic operators
====================================================================

In addition to the familiar arithmetic operators like +, -, *, and /,
several other operators exist which act on their input values in
different ways. This section describes the behavior of these operators.

+   
The familiar addition operator. x + y evaluates to an int if x and y
are both ints, or a float if x and y are both floats. If one of x or y
is a float, then both are converted to floats (with possible loss
of precision in the process) and then x + y is evaluated as a sum
of floats.

- 
The familiar subtraction operator. As with addition, x - y evaluates
to an int if x and y are both ints, or a float if they are both floats.
If one of x or y is a float, they are both converted to floats and the
subtraction is performed as a subtraction of floats.

- 
If - appears in a context where the subtraction operator is not
appropriate, it is interpreted as the negation operator. That is, given input x, "-x" represents the value -x. Returns the same type as x's.

* 
The multiplication operator. The behavior is similar to the + and -
operators.

/
The division operator. If x and y are both ints, then x/y gives the
number of times that y goes evenly into x. For instance, 7/2 = 3,
because 2 goes into 7 three times (with a remainder of 1 which is
discarded). If x and y are both floats, then x/y returns a float. For
instance, 7.0/2.0 = 3.5. Finally, if one of x or y is a float, they are both converted to floats before evaluation.
The result of a division by zero will be discussed in the section on
SC values.

%
The remainder or mod operator. If x and y are both ints, x%y returns
an int representing the remainder after performing a division x/y. For
instance, 7%2 = 1, and 23 % 17 = 6. It is an error to use the % operator on float values, or to compute x%0. The result of such operations will be discussed in the section on SC values.

**
The exponentiation operator. If x and y are both ints >= 0, then x**y
gives an int representing x raised to the power of y (we define 0**0 =
1). Otherwise, x**y is computed as an exponentiation of real numbers
(converting x and y to floats first if necessary). The result of an
invalid exponentiation such as -1^.5 will be discussed in the section on SC values.

!
The logical NOT operator. !x evaluates to 0 (int) if x is nonzero,
and 1 (int) if x is zero.

&&
The logical AND operator. x && y evaluates to 1 (int) if x and y
are both nonzero, and to 0 (int) otherwise.

||
The logical OR operator. x || y evaluates to 1 (int) if one or more
of x and y is nonzero, and to 0 (int) otherwise.

^^
The logical XOR operator. x ^^ y evaluates to 1 (int) if exactly one
of x and y is nonzero, and to 0 (int) otherwise.

~
The bitwise NOT operator. ~x inverts the bits of x's binary (two's
complement) representation. It is an error to apply this to a float --
for the result of such an operation, see the section on SC values.

&
The bitwise AND operator. The nth bit of x&y is set if and only if the
nth bits of both x and y are set. Returns an SC value if either of x or y is a float.

|
The bitwise OR operator. The nth bit of x|y is set if and only if the
nth bit of either x or of y (or both) is set. Returns an SC value if either of x or y is a float.

^
The bitwise XOR operator. The nth bit of x^y is set if and only if the
nth bit of exactly one of x and y is set. Returns a SC value if either of x or y is a float.

=
The equality operator. If x and y are both ints or both floats, x = y
evaluates to 1 (int) if x and y are equal, and 0 otherwise. If exactly
one of x or y is a float, then they are both converted to floats before
testing for equality.

:=
The assignment operator. An unredirected variable name (var(n) or fvar(n) for suitable values of n) must appear on the left-hand side. If the left-hand side contains an integer variable, then the right-hand side is truncated to an integer before assignment. If the left-hand side contains a float variable, then the right-hand side is converted to float if necessary before assignment. In both cases, the value of the expression is the value that is assigned to the variable.

!=
The inequality operator. If x and y are both ints or both floats,
x != y evaluates to 1 (int) if x and y are not equal, and 0 otherwise.
If exactly one of x or y is a float, then they are both converted to
floats before testing for equality.

<
The less-than operator. If x and y are both ints or both floats, x <
y evaluates to 1 (int) if x < y, and 0 otherwise. If exactly one of x or y is a float, then they are both converted to floats before testing for equality.

<=
Similar to <, with the exception that if x = y, then x <= y returns
1 (int).

>
The greater-than operator. If x and y are both ints or both floats,
x > y evaluates to 1 (int) if x > y, and 0 (int) otherwise. If exactly
one of x or y is a float, then they are both converted to floats before testing for equality.

>=
Similar to >, with the exception that if x = y, then x >= y returns
1 (int).

=[,]
!=[,]
=[,)
!=[,)
=(,]
!=(,]
=(,)
!=(,)
Interval operators. These take three arguments, x, y, and z. If any of
x, y, or z is a float, they are all converted to floats. After conversion if necessary, x = [y,z] is equivalent to (x >= y) && (x <= z). Similarly, x = (y,z) is equivalent to (x > y) && (x < z). The half-open intervals have the obvious meaning.

The negated interval operators work as follows: x != [y,z] is equivalent (after conversion if necessary) to (x < y) || (x > z).
x != (y,z) is equivalent to (x <= y) || (x >= z). The half-open intervals again have the obvious meaning.

You can view the interval operators as producing the appropriate open, closed, or half-open intervals on the ints or the floats. The = symbol means set membership in this context.

Some restrictions apply on where intervals may be placed in an
expression. See the section on syntax for details.



====================================================================
III. Precedence and associativity of operators
====================================================================

If you consider an expression like 3+2*5, the result is different
depending if you evaluate the * first (yielding 13) or if you evaluate
the + first (yielding 25). To disambiguate expressions such as this,
operators are assigned distinct precedence levels. In this case, the
precedence of * is higher than the precedence of +, so the * is
evaluated first, then the + is applied to the result. So the correct
answer is 13.

If two operators share the same precedence, then the expression is
evaluated from left to right, except for the unary operators and the
assignment operator, which associate right to left. For instance, * and / share the same precedence, so 5.0*5/6 evaluates to 25.0/6, which evaluates to 4.166667.  On the other hand, 5/6*5.0 evaluates to 0*5.0, which evaluates to 0.0.  In contrast, because unary operators associate right to left, -!0 is grouped as -(!0), which evaluates to -(1), which then evaluates to -1.

If part of an expression is grouped in parentheses (), then that part of the expression is evaluated first. For instance, in the expression
(3+2)*5, the + is evaluated first, giving 5*5, which then evaluates to
25. If parentheses are nested, the innermost parentheses are evaluated
first.

Operator precedence is basically the same as in C. The complete list of operator precedence, from highest to lowest, is as follows:

! ~ -  (Unary operators)
**
* / %
+ -
> >= < <=
= != intervals
:=
&
^
|
&&
^^
||

Programmers are encouraged to parenthesize as necessary to maintain
clarity. Otherwise, bugs due to subtle misunderstanding of operator
precedence are almost assured.



====================================================================
IV. Expression syntax
====================================================================

Basically, any normal arithmetic expression is allowable. In addition,
since the relational operators (>, <=, etc.) are viewed as returning
ints, it is possible to operate on their return values, giving some
unusual-looking expressions like

1.0 = (2 = (1 > 0) + !(0 < 1))

The 1 > 0 term evaluates to 1, and the 0 < 1 term evaluates to 0. Hence
!(0 < 1) evaluates to 1, so the expression simplifies to

1.0 = (2 = 1 + 1)

Since 2 = 1 + 1, the term in parentheses evaluates to 1, so the
expression further simplifies (after type conversion) to

1.0 = 1.0

which evaluates to 1 (int), since the equality holds.

A notable restriction in expression syntax is that interval operators
are only allowed to appear on the rightmost side of an expression. If
part of an expression is enclosed in parentheses, then that part is
considered a subexpression, and an interval is allowed to appear on the
right side of that subexpression. So the following is a well-formed
expression, which evaluates to 0:

(1 = [0,2]) = (0,1)

But the following is not well-formed:

1 = [0,2] = (0,1)

In addition, no operator symbols other than = or != may appear before an interval. So an expression like 5 > [0,2], or 4 + [1,4), is not allowed.

In comma-separated parameter lists, such as the arguments to some
function-type triggers or parameters to state controllers, each expression in the list is considered a separate subexpression, and therefore intervals may appear at the end of those subexpressions.



====================================================================
V. Triggers
====================================================================

For historical reasons, two distinct constructs are both called
"triggers." The first is what might be more properly called a
condition-type trigger, and the second is what might be more properly
called a function-type trigger. For instance, in the CNS, a typical
state controller might look like

[State 1234, 5]
type = ChangeState
trigger1 = time = 0
value = 0

The entire line "trigger1 = time = 0" is a condition-type trigger. If
the expression "time = 0" evaluates to a nonzero value, then the
ChangeState controller is executed. If the expression "time = 0"
evaluates to zero, then the ChangeState controller is not executed.
Thus whether the condition is zero or nonzero affects whether the
controller is triggered.

On the other hand, the word "time" appearing in the expression is a
function-type trigger. It returns a value, namely, the amount of time
that the player has been in state 1234. Note that a function-type
trigger doesn't "trigger" anything. It just gives a value that can be
acted on within the expression.

To further illustrate the difference, let us consider a different state controller:

[State 1234, 5]
type = VarSet
trigger1 = 1
v = 0
value = time + 5

Note that the condition-type trigger "trigger1 = 1" now contains no
function-type triggers within it. Since the expression "1" always
evaluates to 1, the controller will be triggered every frame. To
determine what value to assign var0, the expression "time + 5" is
evaluated. The function-type trigger "time" returns the player's
statetime. Then 5 is added and the result is stored in var0.

A complete list of function-type triggers can be found in trigger.doc.

In general, which of the two types of triggers is meant is clear from
context. Where there is some ambiguity, the terms "condition-type
trigger" and "function-type trigger" will be used.



====================================================================
VI. Trigger redirection
====================================================================

In the above example, the time trigger returned the statetime of the
player. But sometimes, one might wish to check the statetime of the
player's target, or the player's parent (if the player is a helper),
etc. This can be accomplished by preceding the trigger name by a keyword indicating whose information should be returned. This process is known as trigger redirection. For example,

5 + parent, time

returns 5 + the player's parent's statetime.

The complete list of redirection keywords is the following:

*) parent
  Redirects the trigger to the player's parent. (Player must be a
  helper.)

*) root
  Redirects the trigger to the root.

*) helper
  Redirects the trigger to the first helper found. See the related
  trigger "NumHelper" in the trigger documentation.

*) helper(ID)
  ID should be a well-formed expression that evaluates to a positive
  integer. The trigger is then redirected to a helper with the
  corresponding ID number.

*) target
  Redirects the trigger to the first target found.
*) target(ID)
  ID should be a well-formed expression that evaluates to a non-
  negative integer. The trigger is then redirected to a target with
  the corresponding targetID. The targetID is specified in the "ID"
  parameter of a HitDef controller.

*) partner
  Redirects the trigger to the player's partner. Normal helpers and
  neutral players are not considered opponents. See the related
  trigger "numpartner" in the trigger documentation.

*) enemy
  Redirects the trigger to the first opponent found. Normal helpers
  and neutral players are not considered opponents. See the related
  trigger "numenemy" in the trigger documentation.
*) enemy(n)
  n should be a well-formed expression that evaluates to a non-
  negative integer. The trigger is redirected to the n'th opponent.

*) enemyNear
  Redirects the trigger to the nearest opponent.
*) enemyNear(n)
  n should be a well-formed expression that evaluates to a non-
  negative integer. The trigger is redirected to the n'th-nearest
  opponent.

*) playerID(ID)
  n should be a well-formed expression that evaluates to a non-
  negative integer. The trigger is redirected to the player with
  unique ID equal to ID. See the "ID" and "PlayerExistID" triggers
  in the trigger documentation.

If the trigger is redirected to an invalid destination (for instance,
if it is retargeted to a helper when none exist), then an error is
returned. See the section on SC values.

Note: multiple redirection (e.g.,  root,target,time) is not currently supported.


====================================================================
VII. SC values
====================================================================

There are several sources of unrecoverable error in expressions. For
instance, one could attempt to divide by 0, evaluate the square root of a negative number, or attempt to redirect a trigger to a nonexistent destination. In these situations, SC values are used as a way to complete expression evaluation gracefully.

An SC value is a special kind of int which can only take on the values 1 or 0, called SC true (STrue) and SC false (SFalse). The result of any operation or trigger evaluation on an SC value is that SC value. (In other words, you can think of the SC values as variants on the "bottom" element in computation theory. Semantically speaking, CNS expression evaluation is strict in bottom.) If two SC values are given to the same operator, then the leftmost one takes priority.

For instance, the expression

4 + (1/0)*2

evaluates to 4 + (SFalse) * 2, which evaluates to 4 + SFalse, which
evaluates to SFalse. On the other hand,

STrue / SFalse

would evaluate to STrue, because STrue comes on the left. Finally,

helper, time

would evaluate to SFalse if called with no helpers.

Currently, STrue is unused. Only SFalse is returned in error conditions. This means that any condition-type trigger that causes an error during evaluation will not trigger. So, in

type = ChangeState
trigger1 = helper, statetype = A
value = 0

the ChangeState controller would never be executed if no helpers
existed, because the expression "helper, statetype = A" would evaluate
to SFalse, which is 0.

The documentation on function-type triggers explains exactly when those
triggers will return SFalse.

SC values were originally called short-circuit values, because evaluation on an SC value "short-circuits" and does not act as normal. However, this nomenclature had the potential to cause confusion with short-circuit logical evaluation, so it had to be changed, though not so drastically as to cause further confusion. Hence short-circuit values became SC values. At the moment, SC officially stands for "skip and carry", because when an SC value is encountered, normal calculation is skipped and the SC value is simply carried on. Other possibilities for SC include "semantic codomain" and "so-called". We welcome better suggestions for what SC should stand for.


====================================================================
VIII. More on function-type triggers
====================================================================

Most function-type triggers either take no arguments or take arguments
in a parameter list. For instance, the time trigger takes no arguments, whereas the ifelse trigger takes three arguments

ifelse(exp1,exp2,exp3)

where exp1, exp2, and exp3 are all valid expressions. In this kind of
situation, exp1, exp2, and exp3 are all considered separate subexpressions, so intervals can appear on the rightmost end of each of those subexpressions. The order of evaluation of parameter lists is from left to right.

Due to irregular syntax, some old function-type triggers cannot take
expressions as their arguments. Because of this, they cannot be
integrated into expressions in the standard manner. For nonstandard
triggers of this type, the triggers can only appear with certain sets of operators and arguments (which are outlined in trigger.doc). In
particular, these triggers cannot take expressions as their arguments. For instance,

trigger1 = AnimElem = (1+1)

is an invalid expression.

Old-style function-type triggers appear only in "clauses" (trigger, relational operator, argument). These clauses are treated as a single unit (specifically, a single nullary trigger) for the purposes of expression evaluation. This means, among other things, that the concept of operator precedence is not applicable to operators appearing within an old-style function-type trigger clause. For instance, in

trigger1 = AnimElem = 5 + 4

the expression is broken down into three units:
{AnimElem=5} {+} {4}
The "AnimElem=5" unit is treated as the name of a nullary trigger, hence the + operator does not have precedence over the = appearing within the name "AnimElem=5". In other words, this expression means something like "Execute the trigger called `AnimElem=5', then add 4 to the result."

The list of old-style function-type triggers, and expression-capable replacements if applicable, is as follows:

AnimElem, superseded by AnimElemTime
P1Name, P2Name, P3Name, P4Name
StateType, P2StateType
Command
MoveType, P2MoveType
TimeMod, superseded by the % operator
ProjHit, ProjContact, ProjGuarded; superseded by ProjHitTime,
  ProjContactTime, and ProjGuardedTime



====================================================================
IX. Expressions in state and state controller parameters
====================================================================

For the most part, any parameter to the statedef or a state controller
can be an expression. The exceptions are parameters that are given as
strings. For instance, hit attributes, guardflags, etc. cannot be
specified as expressions. Also, the ForceFeedback controller, as well as the ignorehitpause and persistent parameters to all controllers, are irregular in that they cannot take expressions.

State controller parameters are evaluated at the time the controller is triggered, and are not subsequently re-evaluated unless the controller is triggered again. Parameters that are given as comma-separated lists are evaluated from left to right. To achieve continual evaluation of controller parameters, the controller must be continually triggered.

In the case of certain controllers such as HitDef, it is not always wise to use continual triggering, since this decreases performance and also may lead to undesired behavior. In this case, the programmer may wish to try to delay triggering the HitDef as long as possible, so as to evaluate the HitDef parameters right before they are used.



====================================================================
X. (Advanced) Optimizing for speed
====================================================================

MUGEN evaluates condition-type triggers for a state controller in the following order: First it evaluates triggeralls, from top to bottom. If any of the triggeralls evaluates to 0, the rest of the triggers are skipped and evaluation proceeds to the next controller. If all the triggeralls evaluate to nonzero, then the engine starts to evaluate trigger1's, from top to bottom. If any of these evaluate to 0, then evaluation skips to the first trigger2, and so on. If all the triggers in a block (besides triggerall) evaluate to nonzero, then the state controller parameters are evaluated and the controller is triggered.

In other words, the logical evaluation of triggers is short-circuited.
In C-like notation, this setup might be denoted

  triggerall,1 && triggerall,2 && ... && ((trigger1,1 && trigger1,2
    && ...) || (trigger2,1 && trigger2,2 && ...) || ... )

where (e.g.) trigger1,2 denotes the second trigger1 line, trigger2,1  denotes the first trigger2 line, etc. The logical evaluation of this trigger group would then be short-circuited as in C.

Because of this system, considerable performance gains can be attained by organizing expressions so that the condition-type triggers are as simple, and as few in number, as possible. The bulk of the "work" can be offloaded to the state controller parameters, which are only evaluated once at trigger time, instead of every frame that the player is in the state. For instance,

[State -1]
type = ChangeState
trigger1 = command = "a"
trigger1 = power < 1000
value = 3000

[State -1]
type = ChangeState
trigger1 = command = "a"
trigger1 = power >= 1000
value = 3001

[State -1]
type = ChangeState
trigger1 = command = "a"
trigger1 = power >= 2000
value = 3002

could be more compactly expressed as

[State -1]
type = ChangeState
trigger1 = command = "a"
value = 3000 + (power >= 1000) + (power >= 2000)

Further speedups are possible if triggeralls that are most likely to be false are placed highest in the triggerall block. Similarly, the trigger1 block should be the most likely block to trigger, but within the trigger1 block itself, the triggers that are most likely to evaluate to 0 should be placed highest. For state controllers with many triggers containing duplicated conditions, it may be faster to break the controllers up into two separate blocks, each with its own set of triggeralls.

If you have a complex condition which is being used as the trigger condition for many consecutive state controllers, you may wish to save the value of the condition in a variable, then use that variable as a trigger to the subsequent controllers. For instance,

trigger1 = (command="abc" && command!="holddown" && power>=1000) ||       
           (command="abc" && command!="holddown" && var(5)) ||
           ((command != "abc" || command = "holddown") && power>=2000)

could be written as (assuming var(0) is available):

trigger1 = (var(0):=(command="abc" && command !="holddown") && power>=
           1000) || (var(0) && var(5)) || (!var(0) && power>=2000)

Finally, since the expression parser performs no optimization on expressions, an expression like

trigger1 = ctrl

is slightly faster than

trigger1 = ctrl = 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.

JustNoPoint

Ah, that's all in CNS anyway. Thanks. BTW, the edit I made to your post was merely to turn off smileys.

gabe555

Hello it's been a month since I'm a back to MUGEN, and I missed the "spotlight's moment of SFF V2", so..
Could anyone just explain the special features and/or diferences between a normal SFF and stuff..?
And How do I upgrade my current SFF to SFF v2? is it necessary to make a new one from scratch?


- I'm in the correct section right?

Felkazz

Advantages of using SFFV2:

  • can contain PNG sprites in addition to PCX
  • can contain your palettes (no need for .act files)
  • your small portrait (9000,0) does not share colors with your character (you can use any image you want for your small portrait)
  • can contain 24 bit (RGB) and 32 bit (RGBA) sprites (but only MUGEN 1.1 can display these)

To convert just the SSF to SFFV2:

  • Open the SFF using Fighter Factory 3
    Spoiler (click to show)
  • Add your palletes
    Spoiler (click to show)
  • Click to save the SFF
    Spoiler (click to show)
  • Choose the format you want
    Spoiler (click to show)

Now, if you are converting a char, open the entire char on FF3, make sure to set the correct mugenversion (1.0 or 1.1) and the localcoord on it's .def file
Spoiler (click to show)
The localcoord indicates the resolution the char is supposed to work with, if you're converting from an existing character, the localcoord will probably be 320,240

Also, as there are no more .act files, remove them from the .def and add the Pallete Keymap section like this
Spoiler (click to show)
In my example, if the player presses "x" while choosing the char, it will use pallete number 1, the "x2" means that the player must press "s" and "x" to choose that pallete

Now, if your char is using a custom common.cns (or, more spefically, a custom state 5900), you will need to add this to the state 5900:

[State 5900, 3] ;Change palette
type = RemapPal
trigger1 = 1
source = 1,1
dest = 1,palno

Now, just save the char and it should ask which format of SFF you want to use.

That is it, I hope this helps you ^^

Jesuszilla

I consider the SFF containing palettes a disadvantage, actually. It makes it harder for palette creators and selecting a set of 12 palettes from a large set.

I also hate that the 9000,0 doesn't share colors in 1.1. It ruins the point of making a nice small portrait.


Unless you want to do on-the-fly palette swapping, there is absolutely no advantage to using SFFv2 other than better compression.

gabe555

#10
Quote from: Thunderbert on July 08, 2016, 05:51:35 AM
Advantages of using SFFV2:

  • can contain PNG sprites in addition to PCX
  • can contain your palettes (no need for .act files)
  • your small portrait (9000,0) does not share colors with your character (you can use any image you want for your small portrait)
  • can contain 24 bit (RGB) and 32 bit (RGBA) sprites (but only MUGEN 1.1 can display these)

YYes, that was the info I was looking for, thank you.
I was running FF3 couple days ago since I wanted to check out some sff v2's characters
do you see any disadvantage on using V2 format?
My current work is only compatible with 1.0 even though I'm using 1.1 to test my character against other ones.  :P
I think if I upgrade the SFF won't change that much
And there was something making noise on my about something you said:

Quote from: Thunderbert on July 08, 2016, 05:51:35 AM
can contain 24 bit (RGB) and 32 bit (RGBA) sprites (but only MUGEN 1.1 can display these)

you mean I can use a png rgb image for my stage works aimed for 1.1?  :o


Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
I consider the SFF containing palettes a disadvantage, actually. It makes it harder for palette creators and selecting a set of 12 palettes from a large set.
Oh god, I used to sepair each body part colour by colour

Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
Unless you want to do on-the-fly palette swapping, there is absolutely no advantage to using SFFv2 other than better compression.

Oh, I've randomly read about that compression, would make a difference, I got a considerable size on my actual sff, that could help.


JustNoPoint

I merged this here because it's good info for the MUGEN Class

Felkazz

Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
I consider the SFF containing palettes a disadvantage, actually. It makes it harder for palette creators and selecting a set of 12 palettes from a large set.
I can see why it is harder for palette creators, but I don't see the problem with selecting a set of 12 palettes from a large set... If the palettes are well organized, it shouldn't be a problem... Unless I missunderstood your point...

Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
I also hate that the 9000,0 doesn't share colors in 1.1. It ruins the point of making a nice small portrait.
I don't see your point here... I mean, you can still make your nice small portrait using the same colors as the char, but it also allows you to use a completely different one.

Quote from: gabe555 on July 08, 2016, 06:52:54 AM
you mean I can use a png rgb image for my stage works aimed for 1.1?  :o
Yes, you can, but I don't know if there is any extra thing you need to do in order to use them, I have never used one myself...

gabe555

Quote from: Just No Point on July 08, 2016, 03:53:01 PM
I merged this here because it's good info for the MUGEN Class

Cool  ;)

Quote from: Thunderbert on July 08, 2016, 08:14:19 PM
Quote from: gabe555 on July 08, 2016, 06:52:54 AM
you mean I can use a png rgb image for my stage works aimed for 1.1?  :o
Yes, you can, but I don't know if there is any extra thing you need to do in order to use them, I have never used one myself...

Alright, I'll give a try to those projects stages I abandoned time ago since I could'nt handle color loss


Jesuszilla

Quote from: Thunderbert on July 08, 2016, 08:14:19 PM
Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
I consider the SFF containing palettes a disadvantage, actually. It makes it harder for palette creators and selecting a set of 12 palettes from a large set.
I can see why it is harder for palette creators, but I don't see the problem with selecting a set of 12 palettes from a large set... If the palettes are well organized, it shouldn't be a problem... Unless I missunderstood your point...
You have to select the palettes through code if you have more than 12 and you want your users to actually be able to select them. It's not as easy as changing the filename in the .def.


Quote from: Thunderbert on July 08, 2016, 08:14:19 PM
Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
I also hate that the 9000,0 doesn't share colors in 1.1. It ruins the point of making a nice small portrait.
I don't see your point here... I mean, you can still make your nice small portrait using the same colors as the char, but it also allows you to use a completely different one.
What? You could ALWAYS use a shitty 25x25 portrait that doesn't share at all; ⑨ did that all the time in his Melty Blood characters even in WinMUGEN. As a small portrait creator, I like it when characters have proper small portraits (not cropped sprites) that properly change with the character palette. 1.1 doesn't do that and that's what irritates me.

Niitris

#15
As someone who finally got the dynamic of how exactly SFFv2 handles things, I can without question say that the older format is far more convenient, newb-friendly (most important), and less of a pain in general. Only issue is having more ACTs than necessary but swapping between them is simple, as opposed to having to open the SFF for new palettes.

Felkazz

Quote from: Jesuszilla on July 09, 2016, 01:08:15 AM
Quote from: Thunderbert on July 08, 2016, 08:14:19 PM
Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
I consider the SFF containing palettes a disadvantage, actually. It makes it harder for palette creators and selecting a set of 12 palettes from a large set.
I can see why it is harder for palette creators, but I don't see the problem with selecting a set of 12 palettes from a large set... If the palettes are well organized, it shouldn't be a problem... Unless I missunderstood your point...
You have to select the palettes through code if you have more than 12 and you want your users to actually be able to select them. It's not as easy as changing the filename in the .def.
Oh, I get it now... I never had this problem before because I never make a lot of palettes... But now I can see how the old SFF is waaay more convenient than the SFFv2

Quote from: Jesuszilla on July 09, 2016, 01:08:15 AM
Quote from: Thunderbert on July 08, 2016, 08:14:19 PM
Quote from: Jesuszilla on July 08, 2016, 05:59:06 AM
I also hate that the 9000,0 doesn't share colors in 1.1. It ruins the point of making a nice small portrait.
I don't see your point here... I mean, you can still make your nice small portrait using the same colors as the char, but it also allows you to use a completely different one.
What? You could ALWAYS use a shitty 25x25 portrait that doesn't share at all; ⑨ did that all the time in his Melty Blood characters even in WinMUGEN. As a small portrait creator, I like it when characters have proper small portraits (not cropped sprites) that properly change with the character palette. 1.1 doesn't do that and that's what irritates me.
I never noticed that on MUGEN 1.1 and now I don't like this "feature" anymore... I assumed it wasn't possible before because I have aways seen people having problems with palettes on sprite 9000,0 and it was solved by making the sprite has the same palette as the char...
Well, looks like I have more things to learn about the SFF xD

JustNoPoint

I find the new method of adding palettes much simpler. I much prefer sffv2 for that reason.

Make a bunch of gif files that have indexed images of the palettes you want with their names and you just grab them all into the sff with FF3. No having to convert them all to .act or anything. Keep the images in the released char so ppl can visually see what palette they will get and all they have to do to change it is alter thepal number in the .def

Jesuszilla

The palettes are all the same format; just a 768 byte file of 256 colors. The ACT format is good at what it does. It's simple and easy to work with, whether you're a developer or a designer.

JustNoPoint

I didn't know an easy way to batch save .act files from images ppl make when they give palettes.