Skip to content

Slightly more advanced API usage

IonutParau edited this page Sep 26, 2021 · 5 revisions

Here is some thigns that the average mod might never use or use very little of.

So, here are some cool functions your mod can use in the return table to create some cool effects:

onPlace

This function is called when a user places a cell. It gets the id of the cell that was pressed, the x it was placed on, the y it was placed on, a table containing the properties of the cell before it, and the initial at that position before it (as mods might be interested in what was there saved in the initial before it was overwritten as onPlace is called after the cell is overwritten and the cell in initial is overwritten)

customdraw

This method from your mod is called after all rendering is done. It can render on top of EVERYTHING.

onCellDraw

This function has 4 parameters. The ID of the cell it has rendered, the x, the y, and the direction. This is called after the cell is rendered. If you use Love2D's functions for rendering in this function, you can draw on top of cells, which is pretty cool.

onReset

Called when a user resets the grid to the initial state (using the reset button).

onSetInitial

Called when the user sets initial using the Set Initial button.

onClear

Called when the user clears the grid.

onMouseScroll

Called when the user scrolls the mouse cursor. This one has 2 parameters, the x and the y, which are basically the amount.

onCellGenerated

Called when a cell is generated by a generator cell. Has 6 parameters, gets the generator id, its x, its y, the id of what was generated, its x, its y.

onUnpause

Called when the user presses the pause/unpause button to pause/unpause the game.

onMousePressed

Called when the user presses a mouse button. Has 5 arguments, the x of the mouse, the y of the mouse, the button pressed, if it was a touch and how many presses where done at a time.

onMouseReleased

Called when the user releases a mouse button. Has 5 arguments, the x of the mouse, the y of the mouse, the button pressed, if it was a touch and how many presses where released at a time.

Clone this wiki locally