Behavior

From Sandboxels Wiki
(Redirected from Behaviors)
Jump to navigation Jump to search

A behavior is a ruleset for how an Element moves, like Powder or Liquid.

Behaviors are mostly defined in 3x3 grids and constructed of rules, but some are functions.

Default behaviors

There are 36 default behaviors, that you can access from behaviors object (e.g. behaviors.POWDER)

Name Description Example
POWDER_OLD Default behavior of powders before Version 1.6 -
POWDER Default behavior of powders Sand
AGPOWDER POWDER_OLD behavior with reversed gravity (powder goes up) Antipowder
LIQUID_OLD Default behavior of liquids before Version 1.6 -
LIQUID Default behavior of liquids Water
SUPERFLUID_OLD This behavior was never used in the game, and has been added at the same time as SUPERFLUID (Version 1.8.2). It is a superfluid version of LIQUID_OLD -
SUPERFLUID Superfluid version of LIQUID Liquid Light
LIGHTWEIGHT Elements with this behavior fall slower and in a more random pattern Feather
SLIDE This behavior is similar to SUPERFLUID_OLD, and has never been used in the game -
AGLIQUID LIQUID_OLD behavior with reversed gravity (liquid goes up) Antifluid
WALL Default behavior of solids Wall
SLIDE Behavior similar to SUPERFLUID_OLD -
UL_UR Behavior of Fire before Version 1.8.1 -
UL_UR_OPTIMIZED Behavior of Fire Fire
GAS_OLD Default behavior of gases before Version 1.6 -
GAS Default behavior of gases Steam
DGAS Behavior similar to GAS_OLD; pixel has 5% chance of deleting itself every tick Smoke
SUPPORT Elements with this behavior can float if they are connected to a floating element on both sides, otherwise they fall straight down Mudstone
SUPPORTPOWDER Element with this behavior can float if they are connected to a floating element on both sides, otherwise they fall like a powder Packed Snow
DELETE Elements with this behavior all neighboring pixels (without diagonals) Void
FILL Elements with this behavior clone themselves into all neighboring pixels (without diagonals) Filler
CLONER Elements with this behavior clone the first pixel that touches them into all neighboring pixels (without diagonals) Cloner
STURDYPOWDER Elements with this behavior fall straight down Mud
SELFDELETE Elements with this behavior delete themselves -
FOAM Default behavior of Foam Foam
BUBBLE Default behavior of Bubble Bubble
STICKY Elements with this behavior stick to other elements Glue
MOLTEN Default behavior of molten elements Magma
RADPOWDER Behavior similar to POWDER_OLD; pixel has 1% chance of creating radiation Rad Shard
RADMOLTEN Behavior similar to MOLTEN; pixel has 1% chance of creating radiation Molten Uranium
RADLIQUID Behavior similar to LIQUID_OLD; pixel has 2% chance of creating radiation -
BOUNCY Elements with this behavior fly around the screen and can bounce off other pixels Laser
FEEDPIXEL Behavior used in reactions; allows animals to eat other pixels Worm + Nut reaction
KILLPIXEL1 Behavior used in reactions; kills the current pixel -
KILLPIXEL2 Behavior used in reactions; kills the other pixel Dioxin + Head reaction
FLY Default behavior of some flying insects Bee
CRAWLER Default behavior of ants; elements with that behavior can crawl through Dirt, Sand, Clay Soil, Gravel, Mulch, Color Sand and Grass Ant

Rules

Colons

Data (usually element names) can be specified by placing it after a colon (e.g. DL:iron). The effects vary depending on the behavior rule.

For HT and CO, a number can be specified (the amount by which the temperature is changed), but non-numeric values are ignored.

Angle bracket

Additional data can also be specified with the > symbol; the effects also vary depending on the behavior rule. This is seen in CH and EX (e.g. Rotten Meat's CH:meat>rotten_meat%1 and Cold Bomb's EX:10>cold_fire).

Commas

In the above constructs, multiple elements can be specified separated by commas (e.g. DL:fire,smoke to delete fire and smoke). Element names can be repeated in these lists, which might or might not have an effect depending on the rule.

Percent sign

The chance of a rule being applied can be specified by appending the percent sign and a number, which represents the percent chance per tick of the rule happening. An element with the behavior

[
    ["XX","XX","XX"],
    ["XX","DL%50","XX"],
    ["XX","XX","XX"]
]

has a 50% chance of deleting itself each tick.

AND

Multiple rules can be specified for the same position, separated by " AND " (spaces included). Rules are evaluated in order from left (first specified) to right (last specified).

Nonexistent rules

Nonexistent rules are ignored.

Form

Behaviors are initially defined in the form

[
    "AA|AA|AA",
    "AA|AA|AA",
    "AA|AA|AA"
]

(AA = any rule)

When behaviors are parsed on load, they are automatically converted to 2-dimensional arrays; this is the form in which they will be listed in the examples below.

The position in the middle represents a given pixel itself, and the eight positions around them represent the eight places where pixels can be around them.

XX

XX in a behavior means that nothing is specified. The element Wall has a behavior of

[
    ["XX","XX","XX"],
    ["XX","XX","XX"],
    ["XX","XX","XX"]
]

which means that it stays still and do nothing (as it has no tick functions or reactions)

M1 and M2

M1 means that a pixel will move there with first priority, while M2 indicates a second priority move. If a pixel with M2 positions fails to move into an M1 position (because there is a pixel or boundary in the way), it will try to move into an M2 position. If there are multiple M1 or M2 positions specified in a behavior, one will be chosen at random.

An example, the old behavior of sand, is given in a comment within the game's code (it currently uses an equivalent tick function).

/* Behavior Example (Sand)
        [
            ["XX","XX","XX"],
            ["XX","XX","XX"],
            ["M2","M1","M2"]
        ]                    */

Sand pixels will first attempt to move straight down; if they're blocked, they instead try falling to the bottom left or bottom right (chosen randomly).

SP

A pixel with SP (Support) in its behavior will not move if every SP position has a pixel in it (the edges of the canvas don't count.) For instance, consider mudstone, whose behavior is

[
    ["XX","XX","XX"],
    ["SP","XX","SP"],
    ["XX","M1","XX"]
]

A mudstone pixel will fall straight down unless it has pixels (of any elements) on each side.

If an element is specified, SP will only apply if the specified positions are of the specified element (e.g. an element with SP:iron will only be supported if the pixels in the SP:iron position are iron). This doesn't seem to work with multiple elements (e.g. SP:iron,mudstone).

SA

A pixel with SA (Support Any) in its behavior will not move if any of its SA positions have a pixel in them (the edges of the canvas don't count.) An element with the behavior

[
    ["XX","XX","XX"],
    ["SA","XX","SA"],
    ["XX","M1","XX"]
]

would fall straight down unless it has any pixel(s) on its sides.

Unlike SP, element specifications are ignored.

DL

DL (Delete) in a position means that any pixel there will be deleted. If elements are specified (e.g. DL:water or DL:sugar,mud), only pixels of those elements will be deleted.

A pixel that only deletes itself, like Pointer, would have the behavior

[
    ["XX","XX","XX"],
    ["XX","DL","XX"],
    ["XX","XX","XX"]
]

and a pixel that deletes those adjacent to it (i.e. Void), will have

[
    ["XX","DL","XX"],
    ["DL","XX","DL"],
    ["XX","DL","XX"]
]

DL is programmed to ignore itself.

DB

Pixels with DB (Delete Both) in their behaviors will delete themselves and the pixel(s) in the DB position(s). Multiple DB positions in the same behavior are applied with some inconsistency.

DB in the center position has no effect, and DB is also programmed to ignore itself.

CL

If a pixel has CL (Clone) in its behavior, it will create a pixel of its same element in that position. An element with the behavior

[
    ["XX","XX","XX"],
    ["CL","XX","XX"],
    ["XX","XX","XX"]
]

will create more of itself to its left until it is blocked. Filler, whose behavior is

[
    ["XX","CL","XX"],
    ["CL","XX","CL"],
    ["XX","CL","XX"]
]

spreads infinitely by filling the adjacent pixels with itself.

CF

If a pixel has CF (Clone First) in its behavior, it will store the first pixel that it touches (excluding the cloning element itself, elements mentioned in ignore array and Wire). The positions are read in a certain way:

  1. Store the pixel on top.
  2. If there is no pixel on top, store the pixel to the left.
  3. If there is no pixel to the left, store the pixel on the right.
  4. If there is no pixel to the right, store the pixel below it.

Once a pixel is chosen, it will be created perpetually from all positions that had a CF.

Additionally, the selection of pixels spreads through the entire cloning body; placing a large square of Cloner, touching water to it, and erasing a hole deep in the center will result in water being cloned in that hole.

Cloner's behavior is

[
    ["XX","CF","XX"],
    ["CF","XX","CF"],
    ["XX","CF","XX"]
]

which means that the first pixel to touch it will be cloned on the cloner's sides.

CH

CH (Change) in a behavior means that any pixel in the corresponding position will be replaced with the given element.

The element that things will change into is separated with a colon. An element with the behavior

[
    ["XX","CH:iron","XX"],
    ["CH:iron","XX","CH:iron"],
    ["M2","M1 AND CH:iron","M2"]
]

will be a powder that turns anything it touches to iron (behaving unpredictably with itself unless it is explicitly told to ignore itself).

An element with

[
    ["XX","XX","XX"],
    ["XX","CH:sand","XX"],
    ["XX","XX","XX"]
]

will immediately turn into sand.

Multiple elements to change into can be specified with commas; the result will be chosen randomly.

The colon can be used in conjunction with the > sign can be used to specify a "target" element so that only the target can be changed; for instance, the rule CH:water>alcohol will cause water in the rule's position to be changed to alcohol.

In this case, the element (list) immediately after the colon is what is being changed, and the elements after the > are what it is being changed into; this is different from rules without the >, where the thing after the colon is what that pixel is being changed into.

These can be combined. For instance, an element with the behavior

[
    ["XX%0000000000000000000000000000000000000000","CH:lead,tin,iron,copper,mercury>gold,silver","XX%0000000000000000000000000000000000000000"],
    ["CH:lead,tin,iron,copper,mercury>gold,silver","XX%0000000000000000000000000000000000000000","CH:lead,tin,iron,copper,mercury>gold,silver"],
    ["XX%0000000000000000000000000000000000000000","CH:lead,tin,iron,copper,mercury>gold,silver","XX%0000000000000000000000000000000000000000"]
]

(padded for readability) will change any pixels of lead, tin, iron, copper, or mercury into random gold and silver.

(It should be noted that reactions are more efficient for changing things.)

CH without a colon will cause the canvas to turn black and the game to stop responding.

CH example summary

Single element without angle bracket

CH:dirt
Any element in the position of this rule will be changed into dirt.

Element list without angle bracket

CH:dirt,sand
Any element in the position of this rule will be changed into dirt or sand. Which of the two it is changed into will be picked randomly.

Single elements with angle bracket

CH:rainbow>static
Any rainbow in the position of this rule will be changed into static.

Angle bracket with list to the left and single element to the right

CH:rainbow,static>border
Any rainbow or static in the position of this rule will be changed into border.

Angle bracket with single element to the left and list to the right

CH:rainbow>static,border
Any rainbow in the position of this rule will be changed into static or border. Which of the two it is changed into will be picked randomly.

Element lists with angle bracket

CH:rock,sand>zinc,sponge
Any rock or sand in the position of this rule will be changed into zinc or sponge. Which of the two it is changed into will be picked randomly.

C2

An element with C2 (Change Self after M2) in its behavior will change into the specified element after it does an M2. The pixel will change regardless of where in the behavior the C2 is. When there are multiple C2's in a behavior, the bottom right position takes precedence, followed by the bottom center, bottom left, middle right... from bottom to top and right to left.

If multiple elements are given with commas, they will be chosen randomly as with CH.

C2 without any elements specified will also cause a black error canvas.

CR

CR (Create) in an element's behavior means that the specified pixel will be created in the position, with lists being chosen from randomly. When no elements are specified, it defaults to the element itself (like CL).

LB, L1, and L2

When an element with LB (Leave behind [a pixel] when moved) in its behavior will leave behind a pixel of the specified element after moving. This will happen regardless of where in the behavior the C2 is, but the code comment with behavior instructions advises putting LB's in the center. When there are multiple L2's in a behavior, they are prioritized in the same order as C2's. When no element is specified, LB has no effect.

Lists are chosen from randomly.

L1 and L2 are like LB, but only apply to M1 and M2 moves, respectively.

SW

SW (Swap) in a behavior means that an element will swap with whatever element is specified.

An element with

[
    ["XX","SW:wood","XX"],
    ["XX","XX","XX"],
    ["M2","M1","M2"]
]

will fall down like sand unless there is wood above it, in which case it will switch places upwards through the wood.

If multiple elements are specified, it will swap through all of the elements specified.

HT and CO

HT (Heat) in a behavior means that an element will heat whatever pixel is in that position, and CO (Cool) will cool that pixel. A colon can be used to specify a number (e.g. HT:3), which will be the amount by which the pixel is heated/cooled, in °C. However, you cannot specify only (a) certain element(s) to be heated/cooled.

CC

CC (Change Color) in a behavior means that an element will change the color of whatever pixel is in that position to the specified color. The color must be a valid hex triplet (e.g. #FFFFFF), though the # symbol is optional.

ST

ST (Stick) is like SA, but without sticking to itself.

SH

SH (Shock) in a behavior means that an element will electrically charge whatever pixel is in that position, depending on its conduct value. If an element is specified, only that element will be shocked; however, like with Support, this doesn't work with lists.

FX and FY

FX (Flip X) in a behavior means that it will flip across the X axis. For instance, a behavior of

[
    ["XX","M2","XX"],
    ["XX","FX","M1"],
    ["XX","M2","XX"]
]

would become

[
    ["XX","M2","XX"],
    ["M1","FX","XX"],
    ["XX","M2","XX"]
]

.

FY (Flip Y) is the same over the Y axis.

FX has no effect unless the element's flippableX property is true. This also applies to FY with flippableY. However, existing flipX or flipY values would still apply.

RT

(This section is incomplete.)

RT (Rotate) in a behavior means that the pixel's r value will increase and it will operate with an accordingly rotated behavior.

r value Rotation
0
1 90° CCW/ACW
2 180°
3 270° CCW/ACW
Values > 4 are mod 4
(4 → 0, 5 → 1, etc.)

By default, RT will increase r by 1, but specifying a number will increase r by that number; RT:2 specifies a 180° turn.

RT has no effect unless the element's rotatable property is true. However, existing r values would still apply.

BO

BO is like FX or FY, but

  • which axis gets flipped varies depending on its position in the behavior, and
  • it only applies when its corresponding position on the canvas is blocked by a pixel or boundary.

An element with the behavior

[
    ["XX","XX","XX"],
    ["XX","XX","XX"],
    ["XX","M1 AND BO","XX"],    
]

will fall straight down until it hits something. Then, it will bounce, flipping its Y and falling upwards until it hits something else, which makes it fall back down and this cycle to repeat.

If the BO is in the left or right positions, this will happen with the X axis. If it is in the corners, it will happen with both axes. The flippableX and flippableY requirement still applies.

EX

EX in a behavior means that an element will explode when that position has a pixel in it. A numeric radius (e.g. EX:7 is required, and the game will black screen without one. Additionally, a fire substitute can be specified (e.g. EX:10>water), which can be a list. The specified element(s) will replace fire in the explosion.

When an EX rule is in the center, the element will explode immediately. Otherwise, it will explode depending on where pixels are around it; an element with the behavior

[
    ["XX","XX","XX"],
    ["XX","XX","XX"],
    ["XX","M1 AND EX:10>sand","XX"],    
]

will fall down and explode into sand when it lands on something.

Sources: GitHub, experimentation with the game itself