Experience Levelling Up In Flow Battler RPG

Updated 24/09/2022

Series Links

In this tutorial, we will be adding experience and levels to the player. This will give the player a sense of progression as you get stronger and beating enemies becomes easier. To facilitate this we need to store the levels with level thresholds and hold an experience value on each monster. These will be a simple leveling system based around needing to double the amount of experience you have to reach the next level. The Level 2 record will require a threshold of 100 experience points to achieve.

Solution

We will create a number field on the encounters. After this, we will create a metadata object called Levels to hold each threshold and the strength and health increase. We will then make a few changes to the flow to facilitate this and a level-up screen. We will also be creating new variables in the flow to display initial information.

Object Setup

New Field: Experience Value

So you will probably want to play about with this but I have created it as a formula. We will be using the Attack and Health stats as the base for this. Then with some simple maths, we will be multiplying the Attack value by 3 and Health value by 2.5 then adding these together and multiplying them further. This will give you some variety for the Experience Value. This will mean a goblin is worth 28 and a dragon is worth 83 experience points respectively. I have included the formula.

((Attack__c * 3) + (Health__c * 2.5)) * 2.5

Alternatively, you could take the time and create a number input field and assign set values to them to suit your needs as long as it is mapped in the flow further down it won’t make a difference to the flow.

Metadata Object: Level

We will create a very straightforward metadata object to hold the levels for the game. We will call the object Level. We need to add three new number fields the first one is Experience Threshold and this will be used to find which level you are at. (In a later tutorial, this will also be used to unlock spells depending on your level) . The other fields will be to hold Attack and Health increase for this.

NameThresholdAttack IncreaseHealth Increase
Level 1000
Level 210013
Level 321001
Level 442012
Level 584001
Level 6168012
Level 7336001
Level 8672011
Level 91344001
Level 102688011

So with this every other level the attack increases and at every level the health increases for the player with an ever smaller value. So at level 10, your strength will be 10 and you will end up with an additional 13 health. The enemy will feel weak at this point. You will need to populate 10 records in the metadata object.

Flow Updates

Assigning Experience

The first thing we need to do in the flow creates a number variable called Experience this will need a default value of 0 and have no decimal point value. Next, we need to go to the IncrementBattleCount assignment on the Enemy 0 Health and set the experience as a variable and add the {!Get_Enemy.Experience_Value__c}.

Assignment Element with Experience populated.

Displaying Experience

Now we have done this we will add some text to the VictoryScreen to display how much experience we have gained. Adding a space into the display text and typing “You have gained {!Get_Enemy.Experience_Value__c} points.” Next, we need to go to the Game Over screen and add some text for that. Put a line between the existing text add “You fought {!BattleCount} battles.” and on a second line “You gained {!Experience} points”.

Game Over screen with Battlecount and Experience points

I would recommend at this point trying it out a few times to see it all working as intended so far. I noticed the game is pretty hard and I died on the first battle multiple times so we will probably need to make some changes to the stats for the players and enemies.

Adding Leveling Up

Now we have experience running through the game. We can add the leveling up to the game using the metadata object we created. So we need a variable called Level creating which is a text string. We will create another variable called max health as a number variable(18,0) with the player health assigned after the Title Screen this will be used on leveling up. Next, we need to create a get element.

Get Element

Now we need to get the Level object we have created straight after the BattleCount assignment element. The filter criteria will be Experience Threshold is Les Than Or Equal to the Experience variable. We need this to be sorting descending and only retrieve one record. We are using this to get the latest record for this so it will find the highest level that matches the criteria. (Which will be your current level)

We need to create a decision which checks if Level object label matches the Level variable in the flow if it does then you are still the same level. If not you will level up.

Level Up Screen

So we need to create a level up screen to display what we are going to gain this level. “Congratulation you are now {!Check_Level.Label}” then “You have gained {!Check_Level.Attack_Increase__c} Attack and {!Check_Level.Health_Increase__c} Health” and on the next line “Your health has been restored.”

Assign Level Up

So when we level up we want it to update the Level variable to the name of the new level so Level 2, Level 3, etc. MaxHealth wants to increase the Health Increase of level. Player Attack wants to update by the attack increase of the new level and finally, Health wants to replenish to the current level equal to the MaxHealth Variable.

Demostration of experience being met on a new level and increase of stats.

This now covers the leveling up system run through it test it a few times to make sure you are leveling up and restoring health. If you have any issues with it you will need to run it in debug and look for the steps in the tutorial.

Next Steps

In the next tutorial we will add a little bit of flare (literally) by introducing magic which will be usable in battle magic points to case and changes to the battle system it will be a big one so stay tuned.

Published 23/09/2022
Category: Games, Tutorials
Tags: , ,

Other Posts