Difference between revisions of "Lua API:Simulation"

From The Powder Toy
Jump to: navigation, search
(Taking a break, please don't kill me.)
(Mostly documented.)
Line 40: Line 40:
 
  nil sim.createLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number type], [number brush], [number, flag])
 
  nil sim.createLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number type], [number brush], [number, flag])
 
Creates a line of of either the user's currently selected type or the type specified at the specified coordinates.
 
Creates a line of of either the user's currently selected type or the type specified at the specified coordinates.
rx and ry describe the radius of the brush used. Default radius is 5, 5
+
rx and ry describe the radius of the brush used. Default radius is 5, 5.
 
flag refers to particle replacement flags.
 
flag refers to particle replacement flags.
  
Line 68: Line 68:
  
 
=== simulation.decoBrush ===
 
=== simulation.decoBrush ===
  type sim.decoBrush()
+
  nil sim.decoBrush(number x, number y, [number rx], [number ry], [number r, number g, number b, [number a]], [number tool], [number brush])
 
Does something
 
Does something
 +
tool refers to decoration tools.
  
 
=== simulation.decoColor ===
 
=== simulation.decoColor ===
  type sim.decoColor()
+
  number sim.decoColor()
Does something
+
Returns the currently selected decoration color.
 +
 
 +
nil sim.decoColor(number color)
 +
Sets the selected decoration color to color.
 +
color is in the format 0xAARRGGBB
 +
 
 +
nil sim.decoColor(number r, number g, number b, [number a])
 +
Sets the selected decoration color to r,g,b,a
  
 
=== simulation.decoColour ===
 
=== simulation.decoColour ===
type sim.decoColour()
+
Same as sim.decoColor()
Does something
 
  
 
=== simulation.decoLine ===
 
=== simulation.decoLine ===
  type sim.decoLine()
+
  nil sim.decoLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number r, number g, number b, [number a]], [number tool], [number brush])
Does something
+
Changes the decoration color of all particles in the line specified.
 +
rx and ry describe the radius of the brush used. Default radius is 5, 5.
 +
tool refers to decoration tools.
  
 
=== simulation.edgeMode ===
 
=== simulation.edgeMode ===
  type sim.edgeMode()
+
  number sim.edgeMode()
Does something
+
Returns the current Edge Mode
 +
 
 +
nil sim.edgeMode(number mode)
 +
Sets the current Edge Mode to mode
  
 
=== simulation.elementCount ===
 
=== simulation.elementCount ===
  type sim.elementCount()
+
  number sim.elementCount(number type)
Does something
+
Returns the count of the specified type in the simulation.
  
 
=== simulation.floodParts ===
 
=== simulation.floodParts ===
  type sim.floodParts()
+
  number sim.floodParts(number x, number y, [number type], [number cm?], [number flag])
Does something
+
Flood fills either the user's currently selected type or the type specified at the coordinates given.
 +
flag refers to particle replacement flags.
  
 
=== simulation.floodWalls ===
 
=== simulation.floodWalls ===
  type sim.floodWalls()
+
  number sim.floodWalls(number x, number y, [number walltype], [number bm?])
Does something
+
Flood fills either the specified walltype or the type of the basic wall at the specified particle coordinates.
 +
Note: the coordinates might change from particle coordinates to map coordinates in the future.
  
 
=== simulation.getSaveID ===
 
=== simulation.getSaveID ===
  type sim.getSaveID()
+
  number sim.getSaveID()
Does something
+
Returns the SaveID of the currently loaded save or nil if the simulation is not a downloaded save.
  
 
=== simulation.gravMap ===
 
=== simulation.gravMap ===
Line 108: Line 122:
  
 
=== simulation.gravityGrid ===
 
=== simulation.gravityGrid ===
  type sim.gravityGrid()
+
  number sim.gravityGrid()
Does something
+
Returns the current setting for drawing the Gravity Grid.
 +
 
 +
nil sim.gravityGrid(number mode)
 +
Sets the setting for drawing the Gravity Grid to mode.
  
 
=== simulation.gravityMode ===
 
=== simulation.gravityMode ===
  type sim.gravityMode()
+
  number sim.gravityMode()
Does something
+
Returns the current Gravity Simulation Mode.
 +
 
 +
nil sim.gravityMode(number mode)
 +
Sets the Gravity Simulation Mode to mode.
  
 
=== simulation.loadSave ===
 
=== simulation.loadSave ===
  type sim.loadSave()
+
  nil sim.loadSave(number SaveID, [number hideDescription], [number history?])
Does something
+
Loads the save associated with the specified SaveID.
 +
If hideDescription is non zero, the information for the save is not shown.
  
 
=== simulation.loadStamp ===
 
=== simulation.loadStamp ===
Line 128: Line 149:
  
 
=== simulation.neighbours ===
 
=== simulation.neighbours ===
type sim.neighbours()
+
Same as sim.neighbors()
Does something
 
  
 
=== simulation.partChangeType ===
 
=== simulation.partChangeType ===
Line 153: Line 173:
  
 
=== simulation.partNeighbours ===
 
=== simulation.partNeighbours ===
type sim.partNeighbours()
+
Same as sim.partNeighbors()
Does something
 
  
 
=== simulation.partPosition ===
 
=== simulation.partPosition ===
Line 167: Line 186:
 
Get the property value on a particle specified by the index
 
Get the property value on a particle specified by the index
  
The "field" may be a field name or field ID, see [bottom of page] for more information
+
The "field" may be a field name or field ID, see FIELD constants below for valid fields.
  
 
=== simulation.parts ===
 
=== simulation.parts ===
Line 178: Line 197:
  
 
=== simulation.pressure ===
 
=== simulation.pressure ===
  type sim.pressure()
+
  number sim.pressure(number x, number y)
Does something
+
Returns a value on the pressure map.
 +
 
 +
nil sim.pressure(number x, number y, number pressure, [number width, number height])
 +
Sets values on the pressure map.
  
 
=== simulation.prettyPowders ===
 
=== simulation.prettyPowders ===
Line 186: Line 208:
  
 
=== simulation.resetPressure ===
 
=== simulation.resetPressure ===
  type sim.resetPressure()
+
  nil sim.resetPressure()
Does something
+
Resets the pressure map to no pressure.
  
 
=== simulation.resetTemp ===
 
=== simulation.resetTemp ===
  type sim.resetTemp()
+
  nil sim.resetTemp()
Does something
+
Resets the temperature of all particles to their spawn temperature.
  
 
=== simulation.saveStamp ===
 
=== simulation.saveStamp ===
  type sim.saveStamp()
+
  string sim.saveStamp([number x, number y, number width, number height])
Does something
+
Creates a stamp of the specified coordinates. Coordinates default to entire simulation.
 +
Returns the stamp id created.
  
 
=== simulation.toolBox ===
 
=== simulation.toolBox ===
  type sim.toolBox()
+
  type sim.toolBox(number x1, number y1, number x2, number y2, [number tool], [number strength])
 
Does something
 
Does something
  
 
=== simulation.toolBrush ===
 
=== simulation.toolBrush ===
  type sim.toolBrush()
+
  number sim.toolBrush(number x, number y, [number rx], [number ry], [number tool], [number brush], [number strength])
 
Does something
 
Does something
  
 
=== simulation.toolLine ===
 
=== simulation.toolLine ===
  type sim.toolLine()
+
  type sim.toolLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number tool], [number brush], [number strength])
 
Does something
 
Does something
  
 
=== simulation.velocityX ===
 
=== simulation.velocityX ===
  type sim.velocityX()
+
  number sim.velocityX(number x, number y)
Does something
+
Returns an X value on the velocity map.
 +
 
 +
nil sim.velocityX(number x, number y, [number value], [number width, number height])
 +
Sets X values on the velocity map.
  
 
=== simulation.velocityY ===
 
=== simulation.velocityY ===
  type sim.velocityY()
+
  number sim.velocityY(number x, number y)
Does something
+
Returns an Y value on the velocity map.
 +
 
 +
nil sim.velocityY(number x, number y, [number value], [number width, number height])
 +
Sets Y values on the velocity map.
  
 
=== simulation.waterEqualisation ===
 
=== simulation.waterEqualisation ===
  type sim.waterEqualisation()
+
  number sim.waterEqualisation()
Does something
+
Returns the current Water equalisation setting.
 +
 
 +
nil sim.waterEqualisation(number setting)
 +
Set the Water equalisation setting to setting.
  
 
=== simulation.waterEqualization ===
 
=== simulation.waterEqualization ===
type sim.waterEqualization()
+
Same as sim.waterEqualisation()
Does something
 
  
 
== Constants ==
 
== Constants ==

Revision as of 23:36, 29 September 2013

The Simulation API allows for modifying the state and properties of particles, air and gravity

Methods

simulation.adjustCoords

number number sim.adjustCoords(number x, number y)

Does something

simulation.airMode

number sim.airMode()

Returns the current Air Simulation Mode.

nil sim.airMode(number mode)

Sets the Air Simulation Mode to mode.

simulation.ambientAirTemp

number sim.ambientAirTemp()

Returns something

nil sim.ambientAirTemp(number temp)

Sets something

simulation.ambientHeat

number sim.ambientHeat(number x, number y)

Returns a value on the ambient heat map.

nil sim.ambientHeat(number x, number y, number temp, [number width, number height])

Sets values on the ambient heat map.

simulation.clearSim

nil sim.clearSim()

Clears everything on the simulation.

simulation.createBox

nil sim.createBox(number x1, number y1, number x2, number y2, [number type], [number flag])

Creates a filled box of either the user's currently selected type or the type specified at the specified coordinates. flag refers to particle replacement flags.

simulation.createLine

nil sim.createLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number type], [number brush], [number, flag])

Creates a line of of either the user's currently selected type or the type specified at the specified coordinates. rx and ry describe the radius of the brush used. Default radius is 5, 5. flag refers to particle replacement flags.

simulation.createParts

number sim.createParts(number x, number y, [number rx], [number ry], [number type], [number brush], [number flag])

Does something.

simulation.createWallBox

nil sim.createWallBox(number x1, number y1, number x2, number y2, [number walltype])

Creates a filled box of either the specified walltype or the type of the basic wall at the specified particle coordinates. Note: the coordinates might change from particle coordinates to map coordinates in the future.

simulation.createWallLine

nil sim.createWallLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number walltype])

Creates a line of either the specified walltype or the type of the basic wall at the specified particle coordinates. Note: the coordinates might change from particle coordinates to map coordinates in the future.

simulation.createWalls

number sim.createWalls(number x, number y, [number rx], [number ry], [number walltype])

Does something

simulation.decoBox

nil sim.decoBox(number x1, number y1, number x2, number y2, [number rx], [number ry], [number r, number g, number b, [number a]], [number tool])

Changes the decoration color of all particles in the specified coordinates. Although rx and ry are listed here, they are not actually used (bug?). tool refers to decoration tools.

simulation.decoBrush

nil sim.decoBrush(number x, number y, [number rx], [number ry], [number r, number g, number b, [number a]], [number tool], [number brush])

Does something tool refers to decoration tools.

simulation.decoColor

number sim.decoColor()

Returns the currently selected decoration color.

nil sim.decoColor(number color)

Sets the selected decoration color to color. color is in the format 0xAARRGGBB

nil sim.decoColor(number r, number g, number b, [number a])

Sets the selected decoration color to r,g,b,a

simulation.decoColour

Same as sim.decoColor()

simulation.decoLine

nil sim.decoLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number r, number g, number b, [number a]], [number tool], [number brush])

Changes the decoration color of all particles in the line specified. rx and ry describe the radius of the brush used. Default radius is 5, 5. tool refers to decoration tools.

simulation.edgeMode

number sim.edgeMode()

Returns the current Edge Mode

nil sim.edgeMode(number mode)

Sets the current Edge Mode to mode

simulation.elementCount

number sim.elementCount(number type)

Returns the count of the specified type in the simulation.

simulation.floodParts

number sim.floodParts(number x, number y, [number type], [number cm?], [number flag])

Flood fills either the user's currently selected type or the type specified at the coordinates given. flag refers to particle replacement flags.

simulation.floodWalls

number sim.floodWalls(number x, number y, [number walltype], [number bm?])

Flood fills either the specified walltype or the type of the basic wall at the specified particle coordinates. Note: the coordinates might change from particle coordinates to map coordinates in the future.

simulation.getSaveID

number sim.getSaveID()

Returns the SaveID of the currently loaded save or nil if the simulation is not a downloaded save.

simulation.gravMap

type sim.gravMap()

Does something

simulation.gravityGrid

number sim.gravityGrid()

Returns the current setting for drawing the Gravity Grid.

nil sim.gravityGrid(number mode)

Sets the setting for drawing the Gravity Grid to mode.

simulation.gravityMode

number sim.gravityMode()

Returns the current Gravity Simulation Mode.

nil sim.gravityMode(number mode)

Sets the Gravity Simulation Mode to mode.

simulation.loadSave

nil sim.loadSave(number SaveID, [number hideDescription], [number history?])

Loads the save associated with the specified SaveID. If hideDescription is non zero, the information for the save is not shown.

simulation.loadStamp

type sim.loadStamp()

Does something

simulation.neighbors

type sim.neighbors()

Does something

simulation.neighbours

Same as sim.neighbors()

simulation.partChangeType

nil sim.partChangeType(number index, number type)

Reliably change the type of a particle, this method avoids the side effects created by changing the type directly with the "partProperty" method.

simulation.partCreate

type sim.partCreate()

Does something

simulation.partID

number sim.partID(number x, number y)

Get the index of a particle at the specified position

simulation.partKill

nil sim.partKill(number index)
nil sim.partKill(number x, number y)

Reliably delete a particle at a specified index or location, this method avoids the side effects created by changing the type to 0/DEFAULT_PT_NONE with the "partProperty" method

simulation.partNeighbors

number ... sim.partNeighbours(number x, number y, number radius, [number type])

Returns a list of particles indexes that neighbour the given coordinates that matches the given type (if it is specified) The resulting list does not contain the "origin particle"

simulation.partNeighbours

Same as sim.partNeighbors()

simulation.partPosition

number x, number y sim.partPosition(number index)

Get the location of the particle at the specified index

simulation.partProperty

nil sim.partProperty(number index, object field, object value)

Set the property value on a particle specified by index

object sim.partProperty(number index, object field)

Get the property value on a particle specified by the index

The "field" may be a field name or field ID, see FIELD constants below for valid fields.

simulation.parts

type sim.parts()

Does something

simulation.pmap

type sim.pmap()

Does something

simulation.pressure

number sim.pressure(number x, number y)

Returns a value on the pressure map.

nil sim.pressure(number x, number y, number pressure, [number width, number height])

Sets values on the pressure map.

simulation.prettyPowders

type sim.prettyPowders()

Does something

simulation.resetPressure

nil sim.resetPressure()

Resets the pressure map to no pressure.

simulation.resetTemp

nil sim.resetTemp()

Resets the temperature of all particles to their spawn temperature.

simulation.saveStamp

string sim.saveStamp([number x, number y, number width, number height])

Creates a stamp of the specified coordinates. Coordinates default to entire simulation. Returns the stamp id created.

simulation.toolBox

type sim.toolBox(number x1, number y1, number x2, number y2, [number tool], [number strength])

Does something

simulation.toolBrush

number sim.toolBrush(number x, number y, [number rx], [number ry], [number tool], [number brush], [number strength])

Does something

simulation.toolLine

type sim.toolLine(number x1, number y1, number x2, number y2, [number rx], [number ry], [number tool], [number brush], [number strength])

Does something

simulation.velocityX

number sim.velocityX(number x, number y)

Returns an X value on the velocity map.

nil sim.velocityX(number x, number y, [number value], [number width, number height])

Sets X values on the velocity map.

simulation.velocityY

number sim.velocityY(number x, number y)

Returns an Y value on the velocity map.

nil sim.velocityY(number x, number y, [number value], [number width, number height])

Sets Y values on the velocity map.

simulation.waterEqualisation

number sim.waterEqualisation()

Returns the current Water equalisation setting.

nil sim.waterEqualisation(number setting)

Set the Water equalisation setting to setting.

simulation.waterEqualization

Same as sim.waterEqualisation()

Constants

Any of these constants can be accessed with simulation.<constant name here>

DECO

DECO_DIVIDE
DECO_SMUDGE
DECO_ADD
DECO_SUBTRACT
DECO_CLEAR
DECO_DRAW
DECO_MULTIPLY

FIELD

FIELD_DCOLOUR
FIELD_Y
FIELD_TEMP
FIELD_TYPE
FIELD_VY
FIELD_X
FIELD_TMP2
FIELD_TMP
FIELD_FLAGS
FIELD_VX
FIELD_CTYPE
FIELD_LIFE

MAX

MAX_TEMP

MIN

MIN_TEMP

NUM

NUM_PARTS

PT

PT_NUM

R

R_TEMP

TOOL

TOOL_VAC
TOOL_AIR
TOOL_NGRV
TOOL_PGRV
TOOL_HEAT
TOOL_WIND
TOOL_COOL

Uncategorized

YRES
XRES