Skip to content

Basic API Usage part 2

IonutParau edited this page Oct 31, 2021 · 4 revisions

Wait, what?

"I didn't quite understand what the pushability callback does!" - Probably you

Don't worry, I will explain.

The pushability callback

The function in addCell, as I said, was for determining if the cell can be pushed.

It is called the pushability callback.

If the function returns true, the cell is marked as pushable.

The function is called every time a cell tries to push it with PushCell, DoDriller, UpdateMirrors, UpdateGears and PullCell.

What is the information the pushability callback gets?

It should have 7 parameters. Those parameters are:

  • The x coordonate of our modded cell.
  • The y coordonate of our modded cell.
  • The rotation of our modded cell.
  • The x coordonate of the cell pushing us.
  • The y coordonate of the cell pushing us.
  • The direction of the cell pushing us.
  • The type of push that is happening.

The type of push.... what?

The types of push that can happen (in a normal environment) are:

  • "push" for when the cell is pushed by PushCell
  • "pull" for when the cell is pulled by PullCell
  • "gear" for when the cell is moved by a gear
  • "mirror" for when the cell is moved by a mirror
  • "drill" for when the cell is moved by a drill.

If the function returns false or nil then it will not be moved.

What is the type thing for?

The "type thing" is the type property in our options table. It is optional, it defaults to "normal".

The types help CelLuAPI understand what features your cells need.

The types:

  • "normal", the default one. It just means the cell has nothing special.
  • "mover", its a mover! It is made for implementation of biases. Despite the name, it can also be used for things that use PullCell instead of PushCell.
  • "enemy". It means this cell should be like a normal enemy, and trigger the onEnemyDies callback for all mods.
  • "trash". It means this cell should be like a normal trash cell, and trigger the onTrashEats callback for all mods.
  • "diverger". It means this cell should be like a diverger, with its own diverger binding.

How do I give my epic cell a cool diverger binding?

First, the cell needs ot be of type "diverger". Second, you have to call the function bindDivergerFunction.

Example:

bindDivergerFunction(myCoolCellsID, myCoolCellsDivergerFunction)

Ok, but what should the function be?

The function gets two parameters, the x coordonate of the diverger, the y coordonate of the diverger, and the direction the cells are coming from.

You can use that information to return a new direction the cells should be going through, and thus diverge the path. If the function returns nil, the diverger acts like a push cell.

Clone this wiki locally