Repository navigation
Basic API Usage part 3
In the mod's return table, there are functions it has to return.
Here are the callbacks:
Called when the mod is initialized, after all mods have been loaded into memory with their return table.
Called when a modded cell from any mod needs to be updated.
Called when a modded enemy dies.
Called when a modded trash cell dies.
Called when a cell of any kind is placed.
Despite the name, this is called when the user pauses or unpauses the game.
Called when a key is pressed.
Called after rendering a frame.
Called after rendering a cell.
Called when the user clears the grid.
Called when the user resets the grid.
Called when the user sets initial.
Called when a mod uses SetCell to set a cell.
Called when a cell is generated by a generator.
Called when the user presses a mouse button.
Called when the user releases a mouse button.
init is typically used to add all the cells.
update is used to update our modded cells. update gets the ID, x coordonate, y coordonate and rotation of the modded cell it is updating. And thus, you can use if statements to check if its a cell from your mod, and update it based off of which cell it is.
onEnemyDies is used to make modded enemy cells do things when they are destoryed. It gets 6 parameters, the id of the enemy cell, the x coordonate of the cell, the y coordonate of the cell, the entire cell object of the stuff that fell in, the x coordonate the thing that fell in had before falling in, the y coordonate the thing that fell in had before falling in.
onTrashEats is used to make modded enemy cells do things when something falls into them. It gets 6 parameters, the id of the trash cell, the x coordonate of the cell, the y coordonate of the cell, the entire cell object of the stuff that fell in, the x coordonate the thing that fell in had before falling in, the y coordonate the thing that fell in had before falling in.
onPlace is used rarely, but typically to add needed custom properties to modded cells. onPlace gets 6 parameters, the id of the cell placed, the x coordonate where it was placed, the y coordonate where it was placed, the rotation it was placed with, the entire cell object of the original cell, the entire cell object of the original initial cell.
onUnpause is used to do things when the game's paused state is toggled. It gets no arguments.
onKeyPressed is used to do things when a key is pressed.
customdraw is used to draw an overlay, as it is called after the entire frame has been rendered, allowing it to draw on top of absolutely everything.
onCellDraw is used to draw an overlay on cells, typically used in Dynapic Retexturing, which we will cover in the next pages of the API.
onClear is used to maybe clear some variables or do some things when the grid is cleared by the user.
onReset is typically used to reset the values of some variables when the grid is reset by the user.
onSetInitial is kind of used when the mod adds multiple grids to be used at once and make the Set Initial button also set initial of those grids.
onModSetCell is rarely used, and you probably don't need it, as it requires the cell to use setCell. It has 6 parameters, the id the cell has been set to, the x of the cell set, the y of the cell set, the rotation it was set to, the lastvars it was set to and the cell object of the original cell there. This mirrors the arguments of setCell, which are the id to set it to, the x of the cell we want to set, the y of the cell we want to set, the rotation we want to set it to and the lastvars we want to set it to.
onCellGenerated is rarely used, but it could be used to make custom molds.
onMousePressed is mostly used for custom UI buttons. It gets 5 parameters: The mouse's x, the mouse's y, the button pressed, if it was a touch press, and how many presses are happening at once.
onMouseReleased is rarely used. It gets the same parameters as onMousePressed.