script code blocks can be found in a variety of things - such as a timer on a tile type, or in an enemy deffinition, controlling how the enemy looks and behaves.

There are several script commands and they are layed out below:

a script code block consists of:
<command 1> <parameters>
<command 2> <parameters>
....
<command n> <parameters>
0

the 0 specifies the end of the code block.  Here are the set of commands and the parameters the require.


script code blocks are used in various places to make some really cool advanced things happen.

a script code block consists of:
<command 1> <parameters>
<command 2> <parameters>
....
<command n> <parameters>
0

the 0 specifies the end of the code block.

=======================================================================
                       VARIABLES (not implemented yet)
=======================================================================

Scripts can use variables in their processing.

Variables come in 4 flavors...

global scope - global variables which any script can see
local scope - variables which only the tile, enemy or whatever else can see.  useful for if each "thing" needs to store it's own data
file scope - These variables are stored in a file so that the game can remember things after it's shut down such as player data or whatever.

variables look like the following:

scope$variablename

so an example of a variable is:

global$numlives

which is a global scope variable named numlives which might store how many lives the player has for instance

Several commands can be done on these variables to test them or manipulate their values for use in your scripts.

Timers - many things rely on animation timers.  These are just variables that keep track of elapsed time in miliseconds.  They are useful for making things happen based on time such as movement and animation.

=======================================================================
                       Key Codes
=======================================================================

for the commands COMMAND_IFKEYPRESSED and COMMAND_SETKEYSTATUS, they require you to specify which key you are talking about.

If you are talking about a letter key, just use the letter you want to check for.  For instance here is how you would check to see if the player was pressing the T key:

120 t

note that case does not matter so this would also work:

120 T

if you want to check a number key, you can use the number you want to check for like:

120 4

to check if the 4 key was pressed.

If you want to check arrow keys, you use the words "left","right","up" or "down", case does not matter here either so here's how you could check to see if the left arrow key was being pressed:

120 Left

To check the mouse button, you use "MouseLeft", "MouseRight" and "MouseMiddle", so here's how you could check to see if the user was left clicking their mouse:

120 mouseleft

Here are some other symbols...

"Space" - to check the spacebar
"LCTRL", "RCTRL" - to check the right and left control keys
"LSHIFT", "RSHIFT" - to check the right and left shift keys
"LALT", "RALT" - to check the left and right alt keys

=======================================================================
                    SCRIPT COMMANDS
=======================================================================


Here are the set of script commands and the parameters the require.

 Symbolic Command       | Code and params         | Description
------------------------|-------------------------|------------------------------------------------------
COMMAND_ENDCODEBLOCK    | 0                       | this command signifies the end of the code block
COMMAND_CHANGETILE      | 1 <dest tile #>         | this command changes the current tile to another tile.  If this code block is for the <timer> tile event, the tile it would affect is the tile that had the timer event.
COMMAND_CHANGETILE2     | 2 <X> <Y> <dest tile #> | this command changes the block at tile coordinates (X,Y) to tile <dest tile #>.  This is useful for things like if you step on a switch, make it close a door behind you or something.
COMMAND_CHANGEBGCOLOR   | 3 <R> <G> <B>           | this command changes the background color.  R,G and B are decimal numbers between 0 and 1
COMMAND_LOCKCAMERA      | 4                       | this locks the camera in place and doesnt allow screen scrolling
COMMAND_UNLOCKCAMERA    | 5                       | this unlocks the camera and allows scrolling again
COMMAND_SETCAMERA       | 6 <X> <Y>               | this moves the camera to the given X,Y coordinates.  X and Y are in world coordinates (not tile coordinates).
COMMAND_SPAWNENEMY      | 7 <X> <Y> <Type> <Face> | this spawns an enemy at X,Y of type Type, with a face direction of Face. X and Y are in world coordinates (not tile coordinates).
COMMAND_SPAWNEBULLET    | 8 <X> <Y> <Type> <DX>   | this spawns an enemy bullet at X,Y of type Type, moving DX,DY facing Face. X,Y,Type,Face are ints, DX,DY are floats and use small numbers (0.5 is a decent speed). look below for bullet types. X and Y are in world coordinates (not tile coordinates).
                        |   <DY> <Face>           |
COMMAND_SETPLRMOMX      | 9 <Momentum>            | this sets the player's momentum on the x axis to the given value. this is a decimal number
COMMAND_SETPLRMOMY      | 10 <Momentum>           | this sets the player's momentum on the y axis to the given value. this is a decimal number
COMMAND_ADDPLRMOM       | 11 <X> <Y>              | this adds <X> and <Y> to the player's X and Y momentum. X and Y are floats.
COMMAND_SETBGMUSIC      | 12 <music file>         | use this command to change the background music.  set it to the name of a file in the music directory or to "none" (without quotes) to turn off background music.
COMMAND_PLSETR          | 13 <Layer ID> <R>       | Sets the red commponent of a paralax layer
COMMAND_PLSETG          | 14 <Layer ID> <R>       | Sets the green commponent of a paralax layer
COMMAND_PLSETB          | 15 <Layer ID> <R>       | Sets the blue commponent of a paralax layer
COMMAND_PLSETA          | 16 <Layer ID> <R>       | Sets the alpha commponent of a paralax layer
COMMAND_PLSETART        | 17 <Layer ID> <Art>     | Sets the art of a paralax layer, use none for no art
COMMAND_PLSETDEPTH      | 18 <Layer ID> <Depth>   | Sets the depth of a paralax layer
COMMAND_PLSETARTBOX     | 19 <Layer ID> <X1> <Y1> | This command sets the art rectangle of the given paralax layer
                           <X2> <Y2>              |
COMMAND_PLSETASTX       | 20 <ID> <ASTX>          | This sets the texture autoscroll X factor of the paralax layer
COMMAND_PLSETASTY       | 21 <ID> <ASTY>          | This sets the texture autoscroll Y factor of the paralax layer
COMMAND_PLSETASRX       | 22 <ID> <ASRX>          | This sets the rectangle autoscroll X factor of the paralax layer
COMMAND_PLSETASRY       | 23 <ID> <ASRY>          | This sets the rectangle autoscroll X factor of the paralax layer
COMMAND_PLFADECOLOR     | 24 <ID> <RGBA> <Time>   | This command will fade a paralax layer to the given RGBA color over <Time> miliseconds
COMMAND_RANDOM          | 25 <N>                  | This command will randomly execute one of the next N commands and then skip to the N+1'th command and continue execution
COMMAND_CHANGEMULTITILE | 26 <Source> <Dest>      | Change all tiles from <source> to <dest>
COMMAND_PLAYSOUND       | 27 <ID>                 | This command will play sound ID <ID>, this sound must be loaded as part of the map
COMMAND_IFONSCREEN      | 28                      | If the block running the script is on the screen, run the next command, else don't.
COMMAND_IFNOTONSCREEN   | 29                      | If the block running the script is not on the screen, run the next command, else don't.
COMMAND_IFPLAYERNEARER  | 30 <Distance>           | If the player is nearer than <Distance> the next command will be run, otherwise it won't be. <Distance> is in number of tiles
COMMAND_IFPLAYERFARTHER | 31 <Distance>           | If the player is farther than <Distance> the next command will be run, othwerwise it won't be. <Distance is in number of tiles
COMMAND_SPAWNBOSS       | 32 <X> <Y> <Type> <Face>| This command spawns an enemy as a boss.  What this means is that you can set a special script for when the player dies and when the boss dies.  You can also display a life bar.
                        |    <Life> <Win> <Lose>  | <X> and <Y> are the coordinates in world space where you want the enemy to appear (not tile space). <Type> is the type of enemy to spawn. <Face> is the direction you want it to be facing.
                        |                         | <Life> is the type of lifebar you want. 0 = none, 1 = normal.  <Win> is the script that should happen if the player kills the enemy.  <Lose> is the script that should happen if the enemy kills the player.
COMMAND_KILLENEMIES     | 33                      | This makes all enemies inactive. Useful for when you kill a boss so the player can't die after he's won
COMMAND_KILLBULLETS     | 34                      | This makes all bullets inactive. also useful for when you kill a boss
COMMAND_MPTELEPORT      | 35 <ID> <X> <Y>         | this command teleports a moving platform to the specified location. <ID> is the moving platform ID.
COMMAND_MPSETMOVEMENT   | 36 <ID> <X> <Y>         | this command sets the movement vector of a moving platform. 0 0 is stop. <ID> is the moving platform ID.
COMMAND_CHANGEMAP       | 37 <newmap>             | this command changes the map to <newmap>
COMMAND_MOVEPLAYER      | 38 <X> <Y>              | this sets the position of the player to <X>,<Y>



 Symbolic Command            | Code and params         | Description
-----------------------------|-------------------------|------------------------------------------------------
NMECMD_SETLIFE               | 39 <Life>                | This sets the life of an enemy to an amount
NMECMD_SETHITBOX             | 40 <x1> <y1> <x1> <y2>   | This sets the hitbox of an enemy
NMECMD_SETTOUCHDAMAGE        | 41 <Damage>              | This sets the amount of damage an enemy does when you touch it.
NMECMD_INVINCIBLE            | 42 <Invincible>          | Used to set a monster to invincible or not.  1 is invincible, 0 is not.
NMECMD_FLOAT                 | 43 <Float>               | Used to make the enemy ignore gravity and such. 1 is on, 0 is off.
NMECMD_DIEOFFMAP             | 44 <Die>                 | If the enemy should die when it leaves the map, put a 1 here, else put a 0.
NMECMD_COLOR                 | 45 <R> <G> <B> <A>       | Use this to set the color tint of an enemy.
NMECMD_FRAME                 | 46 <Frame Number>        | This sets the enemy's frame number to whatever you specify.  If you set it to -1, nothing will be drawn.
NMECMD_IFANISTATE            | 47 <state>               | This is used to test the enemy's animation state.  If the enemy's anistate is <state> it will do the next set of commands, otherwise skip commands until an NMECMD_ELSE or NMECMD_ENDIF
NMECMD_TILEDIMENSIONS        | 48 <x> <y>              | Use this to set the tile dimensions of the art file
NMECMD_IFANITIMERGT          | 49 <timer> <amount>     | If the anitimer of the enemy is greater than <amount>, do the next set of commands, otherwise skip commands until an NMECMD_ELSE or NMECMD_ENDIF.   <timer> is 1-5 and specifies which timer to do the operation on.
NMECMD_SUBANITIMER           | 50 <timer> <amount>     | Subtract <amount> from the anitimer.  <timer> is 1-5 and specifies which timer to do the operation on.
NMECMD_INCANISTATE           | 51                      | Increment the animation state
NMECMD_ELSE                  | 52                      | In if statements, if an if statement is false, it will skip to an else statement or endif statement, whichever comes first
NMECMD_ENDIF                 | 53                      | In if statements, if an if statement is false, it will skip to an else statement or endif statement, whichever comes first
NMECMD_ADDBLOOD              | 54 <amount> <RGBA>      | This will spawn blood particles where the enemy is at.  <amount> is how many particles and <RGBA> is the color of the blood.
NMECMD_SETANISTATE           | 55 <state>              | Set the animation state to <state>
NMECMD_WALK1                 | 56 <distance>           | This will cause the enemy to walk the way they are facing an amount defined by <distance>.  If they are unable to walk that way, they will turn around.
NMECMD_IFONGROUND            | 57                      | This will execute the next batch of commands if the enemy is on the ground, else it will skip to an else statement or endif statement, whichever comes first
NMECMD_SETANITIMER           | 58 <timer> <amount>     | This will set an animation timer to a specified amount.  <timer> is 1-5 and specifies which timer to do the operation on.
NMECMD_IFFRAMEEQ             | 59 <frame>              | This checks to see if the monster's frame equals <frame>.  if it does, it will execute the next batch of commands.  If it doesn't, it will skip commands until an NMECMD_ELSE or NMECMD_ENDIF.
NMECMD_SETDRAWRECT           | 60 <x1> <y1> <x2> <y2>  | This will set the screen rectangle of the monster's art.  This can be used to make sure the art fits in the hitbox, or for whatever you want.  The default is -25 -25 25 25
NMECMD_SETTIMERRATE          | 61 <timer> <direction>  | This sets a timer to forward, reverse, or stop.  <timer> is 1-5 and specifies which timer to do the operation on. <direction> is how fast you want the timer to run based on regular time. for instance: -1 is reverse, 0 is stop, 1 is normal, 2 is double, 0.5 if half, etc.
NMECMD_IFANITIMERLT          | 62 <timer> <amount>     | If the anitimer of the enemy is less than <amount>, do the next set of commands, otherwise skip commands until an NMECMD_ELSE or NMECMD_ENDIF.   <timer> is 1-5 and specifies which timer to do the operation on.
NMECMD_SETTIMERRANDOM        | 63 <timer> <low> <high> | This sets a timer to a random value between <low> and <high>.  <timer> is 1-5 and specifies which timer to do the operation on.
NMECMD_RANDOM                | 64 <N>                  | This command will randomly execute one of the next N commands and then skip to the N+1'th command and continue execution
NMECMD_SETMOVEY              | 65 <MoveY>              | Set the MoveY of an enemy to a value.  This is mostly useful for swimming and flying.
NMECMD_SETFACEDIRECTION      | 66 <Direction>          | Sets which way the enemy is facing.  -1 for left, 1 for right.
NMECMD_IFLIFEGT              | 67 <Amount>             | If the life of the enemy is greater than <amount>, do the next set of commands, otherwise skip commands until an NMECMD_ELSE or NMECMD_ENDIF.
NMECMD_IFLIFELT              | 68 <Amount>             | If the life of the enemy is less than <amount>, do the next set of commands, otherwise skip commands until an NMECMD_ELSE or NMECMD_ENDIF.
NMECMD_FLY1                  | 69 <Factor>             | This will cause an enemy to fly the way they are facing.  If they are unable to fly the way they are going, there is a 50% chance they will turn around horizontaly or stay their course horizontaly and a 50% chance they will turn around vertically or stay their course vertically.  Note that the enemy moves vertically based on MoveY.
NMECMD_IGNOREPHYSICS         | 70 <Ignore>             | Turn this on if the enemy should ignore all physics.  1 is on, 0 is off, 2 to toggle on/off.
NMECMD_ADDFRAME              | 71 <Amount>             | Adds <Amount> to the current frame
NMECMD_PLAYSOUND             | 72 <SoundName>          | This will play the sound you specify
NMECMD_SPAWNENEMY            | 73 <X> <Y> <enemyname>  | Spawns an enemy with an offset of <X>,<Y> from the current enemy. <enemyname> is the name of the enemy to spawn.
NMECMD_DIE                   | 74                      | This deactivates the enemy.  It runs the enemy die script before killing the enemy as well.
NMECMD_TIMERCOLOR            | 75 <which> <timer>      | This sets a color component of an enemy based on the value of a timer. <which> is which color component to set: 0 = red, 1 = green, 2 = blue, 3 = transparency. <timer> is the timer number to reference.
                             |    <a> <b>              | <a> is the amount to add to the timer value before dividing by <b>. IE:  Component = (timer + <a>)/<b>.  This command is useful for changing colors over time.
NMECMD_TELEPORT              | 76 <X> <Y>              | This moves the enemy to <X>,<Y>, useful for boss fights
NMECMD_FACEPLAYER            | 77                      | This will make an enemy turn and face the player.  Useful for enemies which chase player etc.  Note that when you use this command it's a one time thing.  If you want the enemy to keep facing the player, you will have to use it in the logic loop and make sure it gets run every time
NMECMD_SPAWNBULLET           | 78 <X> <Y> <enemyname>  | This command spawns a bullet at and offset from the enemy of <X> <Y> facing the same direction as the enemy which spawned it with a movement vector of (<MX>,<MY>). <align> is the alignment of the bullet, valid values are: 0 - doesnt hurt anyone (and is neutral passive), 1 - Hurts enemy (and is friendly), 2 - hurts player and anything friendly to the player (and is an enemy), 3 - hurts both friendly and enemy (is neutral aggressive)
                             |    <MX> <MY> <align>    |
NMECMD_FLY2                  | 79                      | This makes an enemy fly based on it's MovX and MovY.
NMECMD_IFFACELEFT            | 80                      | If the enemy is facing left, do the next batch of commands, otherwise skip to and else or endif, whichever comes first.
NMECMD_DEBUGON               | 81 <on>                 | This is used to turn on and off debug.  useful for trying to debug specific enemies. 1 is on, 0 is off
NMECMD_SPAWNBULLETABSOLUTE   | 82 <X> <Y> <enemyname>  | This command spawns a bullet at an absolute position of <X> <Y> facing the same direction as the enemy which spawned it with a movement vector of (<MX>,<MY>).  This is more useful for boss fights etc since it spawns at an absolute location.
                             |    <MX> <MY>            |
NMECMD_IGNOREWALLS           | 83 <on>                 | This command is used to make an enemy ignore walls. 1 for ignoring walls, 0 for not ignoring walls, 2 to toggle.
NMECMD_HOMEONPLAYER          | 84 <magnitude>          | This will set an enemie's MoveX and MoveY to point towards a player.  The vector will be of length <magnitude> which you can use to control speed.  Use a negative magnitude to make the enemy go away from the player
NMECMD_IFPLAYERNEARER        | 85 <distance>           | If the player is closer than <distance> to the enemy, do the next batch of commands. Otherwise skip to and else or endif, whichever comes first.  Distance is measured in world space (1 tile = 25 units)
NMECMD_SETMOMENTUM           | 86 <X> <Y>              | This will set an enemy's momentum to (<X>,<Y>)
NMECMD_ADDMOMENTUM           | 87 <X> <Y>              | This will add <X> and <Y> to the enemy's momentum
NMECMD_MULTMOMENTUM          | 88 <X> <Y>              | This will multiply the enemy's momentum by <X> and <Y>


COMMAND_LOG                  | 89 <message>            | This puts a message in log.txt, useful for debugging. Message must be in quotes ie: "message here".
COMMAND_CHECKPOINT           | 90                      | This command acts as if the player just walked through a level checkpoint so when they die, they will start at this position.
COMMAND_CONFETTIPLAYER       | 91                      | This makes confetti come out of the player.
COMMAND_CONFETTIENEMY        | 92                      | This makes confetti come out of the player.

COMMAND_VARSETCONST          | 93 <var> <constant>     | This sets a variable to a constant.  <variable> is a number 0-255 which says which variable to use. <constant> is an integer.
COMMAND_VARSETVAR            | 94 <var1> <var2>        | This sets the value of variable 1 to the value of variable 2.
COMMAND_VARADDCONST          | 95 <var> <constant>     | This adds a constant to a variable.
COMMAND_VARADDVAR            | 96 <var1> <var2>        | This adds the value of var1 and var2 and stores the result in var1
COMMAND_VARMULCONST          | 97 <var> <constant>     | This multiplies a variable by a constant
COMMAND_VARMULVAR            | 98 <var1> <var2>        | This multiplies the value of var1 and var2 and stores the result in var1
COMMAND_VARLTCONST           | 99 <var> <constant>     | checks if a variable is < a constant
COMMAND_VAREQCONST           | 100 <var> <constant>    | checks if a variable is = a constant
COMMAND_VARNEQCONST          | 101 <var> <constant>    | checks if a variable is != a constant
COMMAND_VARGTCONST           | 102 <var> <constant>    | checks if a variable is > a constant
COMMAND_VARLTVAR             | 103 <var1> <var2>       | checks if a variable is < var2
COMMAND_VAREQVAR             | 104 <var1> <var2>       | checks if a variable is = var2
COMMAND_VARNEQVAR            | 105 <var1> <var2>       | checks if a variable is != var2
COMMAND_VARGTVAR             | 106 <var1> <var2>       | checks if a variable is > var2
COMMAND_PLSETTEXT            | 107 <id> <text>         | This sets the text of a paralax layer marked by id <id> to <text>.  <text> is a quoted string, ie "message here".  If you want to remove text from a paralax layer put ""
COMMAND_PLAPPENDTEXT         | 108 <id> <text>         | This appends text to the end of a paralax layer's text.  <text> is a quoted string, ie "message here".
COMMAND_PLAPPENDVAR          | 109 <id> <var>          | This appends the value of a variable to the end of a paralax layer's text. <var> is the id of the variable to append to the text.
COMMAND_NMESETBULLETFLAG     | 110 <set>               | This sets the flag of the enemy bullet flag.  valid values for <set> are 0,1 and 2.  0 = bullet flag off, enemy is not a bullet.  1 = bullet flag on, enemy is a bullet.  2 = toggle bullet flag so if it's on turn it off, else if it's off turn it on.
COMMAND_NMESETFLAGHURTYOU    | 111 <set>               | This sets the flag that says whether or not the enemy hurts the player.  valid values for <set> are 0,1 and 2.  0 = bullet flag off, enemy is not a bullet.  1 = bullet flag on, enemy is a bullet.  2 = toggle bullet flag so if it's on turn it off, else if it's off turn it on.
COMMAND_NMESETFLAGHURTNME    | 112 <set>               | This sets the flag that says whether or not the enemy hurts enemies.  valid values for <set> are 0,1 and 2.  0 = bullet flag off, enemy is not a bullet.  1 = bullet flag on, enemy is a bullet.  2 = toggle bullet flag so if it's on turn it off, else if it's off turn it on.
COMMAND_NMESETFLAGHURTBYYOU  | 113 <set>               | This sets the flag that says whether or not the enemy is hurt by the player.  valid values for <set> are 0,1 and 2.  0 = bullet flag off, enemy is not a bullet.  1 = bullet flag on, enemy is a bullet.  2 = toggle bullet flag so if it's on turn it off, else if it's off turn it on.
COMMAND_NMESETFLAGHURTBYNME  | 114 <set>               | This sets the flag that says whether or not the enemy his hurt by enemies.  valid values for <set> are 0,1 and 2.  0 = bullet flag off, enemy is not a bullet.  1 = bullet flag on, enemy is a bullet.  2 = toggle bullet flag so if it's on turn it off, else if it's off turn it on.
COMMAND_NMESETROTATION       | 115 <rotation>          | This sets the rotation of the enemy.  rotation is how far it is turned
COMMAND_NMESETROTATION       | 116 <rotation>          | This sets the spin of the enemy.  spin is how much it spins per milisecond
COMMAND_NMESETDIEONWALL      | 117 <on>                | If this is on, the enemy dies when it hits a wall (this is for bullets), if it's off it wont die when it hits a wall, if you put a 2 in <on> it will just toggle this flag
NMECMD_SETMOVEX              | 118 <movex>             |
NMECMD_ADDMOVEXY             | 119 <movex> <movey>     |
COMMAND_IFKEYPRESSED         | 120 <key>               | this returns true if the given key is pressed.  look in the above section for keycodes for more information on how to test for various keys.  If you give an invalid key code it will always report that the key is not pressed.
COMMAND_SETKEYSTATUS         | 121 <key> <status>      | This sets the "pressed" status of a key to what you want to set it to.  For <status> use 0 to mark the key as not pressed, 1 to mark the key as pressed, and 2 to toggle the key pressed status.
COMMAND_FACECURSOR           | 122                     | this makes an enemy turn left or right to face the cursor
NMECMD_SPAWNENEMY2           | 123 <X> <Y> <enemyname> | Spawns an enemy with an offset of <X>,<Y> from the current enemy. <enemyname> is the name of the enemy to spawn.
                             |     <velocity>          | <velocity> is a scalar applied to the vector that points from the enemy and the mouse cursor (it makes the spawned enemy's movx, movy point at the mouse cursor)
NMECMD_SPAWNENEMY3           | 124 <X> <Y> <enemyname> | Spawns an enemy with an offset of <X>,<Y> from the current enemy. <enemyname> is the name of the enemy to spawn.
                             |     <velocity>          | <velocity> is a scalar applied to the vector that points from the enemy and the mouse cursor (it makes the spawned enemy's momx, momy point at the mouse cursor)
NMECMD_AUTOSCROLLCAMERA      | 125                     | auto scrolls the camera - used by player enemy only for the most part to make camera follow player
COMMAND_RESTARTLEVEL         | 126                     | resets the level, used mostly for when the main player dies.
NMECMD_GRAVITY               | 127                     | This changes an enemy's momentum by taking into account the force of gravity
NMECMD_FRICTION              | 128                     | This changes an enemy's momentum by taking into account the force of friction against the ground
NMECMD_AIRFRICTION           | 129                     | This changes an enemy's momentum by taking into account the force of friction against the air