Skip to content

Helper functions

IonutParau edited this page Sep 26, 2021 · 3 revisions

These functions are meant to help your mods do basic stuff. At the end, I also say a fun fact that is the entire idea behind mods like Celodium, BetterChunks and ApX. (some of which are only rumours).

The helper functions and what they do:

CopyTable

This one takes a table and copies it. The reason this is useful is because, in Lua tables are pointers. And thus we can't copy them by setting a variable equal to them. Instead, this function creates a new table with copied properties. It works, even with tables in tables. This one is the main thing used in the mod GridTab.

calculateCellPosition

This one takes the x and y in pixel coordonates and returns a tabe with 2 properties, x and y, in cell coordonates. So the coordonates of a cell that would be rendered there.

setCell

This one takes in 3 obligatory arguments: the x, the y, the id, and 2 optional ones: rotation and lastvars. This one is meant to help you override parts of a cell, like the id to transform it into a different cells, its rotation (tho we do have rotateCell for that), lastvars which contains its last state for the game to smoothly animate the change in position and rotation.

calculateScreenPosition

This one takes the position in cell coordonates and returns the position in pixel coordonates as a table with 2 properties, x and y.

walkDivergedPath

This one is meant to help you with problems encountered with divergers. This one can give you where the path ends. You can use it to get the actual position of it, and not the position of the diverger, which is pretty cool. It has 4 arguments, the x you start from, the y you start from, the x the diverger is at, the y the diverger is at. It returns a table with 2 properties, x and y.

addModdedWall

This one adds a custom wall type that the user can use. This one is an old one, but very few people even know it exists, and only 1 mod uses it.

rotateCell

It takes the x, y and amount to rotate it by and it rotates the cell.

getCellLabelById

It takes the id of the cell and returns the label it is indentified by.

getCellLabel

It takes the x and y and returns the label of the cell in there (using its id).

getCellIDByLabel

It takes the label and returns the id.

addCell

This one is explained in the first page of basic API usage.

Now the fun fact: You can override all functions in CelLuAPI, even the ones of the game, and even the ones of the API. This fact is used in BetterChunks to allow for chunks of any sizes. Its also used in Celodium to change how rendering works. And in ApX its used to add new API features.

Clone this wiki locally