Calculating level-up costs with formulas

Discover additional components and their applications in Machinations to add more features to your level progression system.

This tutorial will introduce you to additional components and their applications in Machinations to add more features to your level progression system.

You will create more complex formulas for level-up costs and use a list of predefined values for XP earned from enemies depending on the player’s level. You will also learn how to make Forecasts for many users.

Let’s assume that we want the cost formula to have the following format:

4 – Calculating level-up costs with formulas
Tip

Whenever you need to create formulas that require special mathematical operators or conditions, you can use Registers. They can alter the state of Nodes or influence the flow of Resources based on the computation of multiple inputs coming from either Nodes in the diagram or your own input during a Play.

This formula will affect the amount of resources transferred from the “XP” pool to the “Level Up” converter. However, this Resource Connection already has a State Connection that is modifying the number of resources transferred. If you want to implement this formula, you have to make the following changes in the diagram:

  1. Select the State Connection “Raise cost”
The State Connection Raise cost selected, drawn as an arc from the Level pool to the Spend resource connection, labelled adds value × 100The State Connection Raise cost selected, drawn as an arc from the Level pool to the Spend resource connection, labelled adds value × 100
  1. Press “Bksp/Del” to remove the connection, or right-click it and select “Delete”.

We first need to reference the “Level” pool to implement the formula. Follow the next steps:

  1. Click the Register icon in the toolbar or use the keyboard shortcut (r).
The toolbar with the Register button outlined in red
  1. Place the Register to the right of the “Level” pool
The new Register placed to the right of the Level pool. It is already linked from Level, so it shows its first input and no error mark; a bare Register is outlined in red until it has an input.The new Register placed to the right of the Level pool. It is already linked from Level, so it shows its first input and no error mark; a bare Register is outlined in red until it has an input.
  1. With the Register selected, type “Next level-up requirement” into the label at the top of the Properties panel (it reads “Add a label” on a new component).
The Properties panel of the Register, with its name “Next level-up requirement” outlined in red, Trigger Passive and the formula round(100*1.25^(lvl-1)).The Properties panel of the Register, with its name “Next level-up requirement” outlined in red, Trigger Passive and the formula round(100*1.25^(lvl-1)).
  1. Add a State Connection (either from the toolbar or using the shortcut “alt+c”) and click on the “Level” pool so that it becomes the origin of the connection.
The Register named Next level-up requirement, with a State Connection from the Level pool that reads Input as aThe Register named Next level-up requirement, with a State Connection from the Level pool that reads Input as a
  1. Click on the Register “Next level-up requirement” so that the State Connection ends at the register.
  1. Have you seen what happened to the State Connection when you clicked on the register? The connection has the name “a” in the box under Type. When you draw a State Connection, it will be given a variable name. By default, the variable name will be alphabetical letters – “a, b, c, d….

    To make the formula easier to read, select the State Connection and, with Type on “Formula input”, type “lvl” into the box under it. State Connections that “enter” registers get the values from the connection’s origin.
The Properties panel of the State Connection with Type “variable” and the name lvl outlined in red.
  1. Add a new State Connection and click on the “Next level-up requirement” register so that it becomes the origin of the connection.
A second State Connection from the Next level-up requirement register to the Spend resource connection, labelled Add changeA second State Connection from the Next level-up requirement register to the Spend resource connection, labelled Add change
  1. Click on the Resource Connection between the “XP” pool and the converter so that the State Connection modifies the target Resource Connection. State Connections that “exit” registers are used to get the value from the register to be used anywhere else. (You can arrange the connection in the canvas so it does not clutter with other components).
  1. Now in the register we must enter the formula defined in the beginning:
In the register we must enter the formula defined in the beginning

Previously, we need to make two considerations:

  • The formula requires the value “Current Level” which is obtained from the “Level” pool. As the State Connection between the “Level” pool and the register is called “lvl”, this means that the current level can be read by using the variable “lvl”.
  • Converters only work correctly when their inputs are rounded and converted into integer values. As a consequence, the formula will be inside a math.js function called “round”.
  • Therefore, select the register and in the Formula field type“round(100*1.25^(lvl-1))”.
  1. Now in the Register we must enter the formula defined in the beginning:
The Properties panel of the Register with the formula round(100*1.25^(lvl-1)) outlined in red.