Lets Make A Fun Adventure Game In Flows

Updated 16/09/2022

You may have seen this from one of my other tutorials. If you haven’t followed along, I recommend checking out my other game tutorials. I made a game and created a series of tutorials on how to make an RPG in salesforce. This tutorial series aims to make a game without that and use pure flow functionality. While this uses no Apex code, I would say this is trickier to follow than the previous one. This game will be something like a text-based adventure a popular tool for making these is twine.

Initial Setup

The game we are making is something like a text adventure. We will add in some graphics at a later point, a map tile image, and any special items you interact with and collect. To get started, we will need to set up some brand new objects and create data before we build a flow.

Object Setup

Map Object

The Map object requires no additional fields and acts as a container for map tiles. This will allow you to hold multiple maps and will allow us to build a traverse map screen. (Like Entering a cave or a different area) Set the Name field as manual input and create a tab using the compass icon.

Map Tile

Map tiles will contain individual tiles of the map. In the example, we will create a three-by-three grid of tiles for the player to travel around. For this, we will use an X and Y value for a row and column; think of a naughts and crosses board with each square having a coordinate.

Map X and Y Values

We need a text field (Long) named Description. This helps build the area by describing it. So something like the following would be an example of this.

You stand at the entrance to a forest; it is dark inside. In the distance, you can see a faint light, possibly from a building. As you are hungry with no food left, this may be your only chance to eat. To the south of you see a do not enter sign for a path that looks to follow the perimeter until it disappears out of sight.

Fields To Create
  • Description – Long Text Field.
  • X – Number(18,0).
  • Y – Number(18,0).
  • Map – Master Detail looking up to Map.

Tile Event

Tile Events hold the available options to do on each tile and will prevent players from wandering off the map and only allow them to traverse to the next place. As these will be called in the flow as a picklist, they will mainly set the paths for East, South, West, and North. At a later stage, we will traverse maps.

Fields To Create
  • Map Tile – Master Detail looking up to Map Tile.
  • Action – Picklist (East, South, West, North).
  • Action Number – Number Formula (See Below).
  • Display Text – Text Field.

Action Formula Field

A relatively simple Case formula to get the picklist directions of East, South, West, and North. This will mean that future formulas in the flow can use the number value. This field is called Action__c.

CASE(TEXT(Action__c),
"East",1,
"South",2,
"West",3,
"North",4,
0)

Data

Now we have created the objects. You can create your own custom map or follow along with the tutorial. You can download the zip file and upload the three tabs into the objects we have just created. You will need to split them out into individual spreadsheets and save them as CSV. You will need to replace the Master-Detail field with the IDs you have uploaded, so start with the Map, then Map Tile, and finally, Tile Event.

Building The Flow

Now we have all the data in place and we are going to create a screen flow, we can start building the flow out first thing to do is create two number variables, XCurrent and YCurrent, which need a default value of 1. These will be used to get the first map tile. For the time being, we will not do anything with the map.

Get Map Tile

Create a Get Records for the object Map Tile where X equals XCurrent and Y equals YCurrent. Leave the rest of the setup as is; this will provide everything for now. Next, create a screen element directly following on from the get records. Create a Display Text and pull through the Description and on the next day, bring through the X and Y value.

Get Tile Map Tile

Create Screen Element

Create a record choice set for Tile Events where the value Map Tile Id equals the Id of the Map tile you have retrieved in the previous record get. Select the Display Name as the label and select the value as Id; under additional variables, use the Action Number Field and create a number variable name Description. Add a picklist called Action, then add the Tile Events record choice set as the choice in the Choice field.

Display Screen

Value Assignment

Updating X and Y Map Coordinates

The following formulas use the Direction variable to update the X and Y values into two formula resources. This will help when we loop back around to get a new location.

If(({!Direction} = 1),{!XCurrent}+1, 
If(({!Direction} = 3),{!XCurrent}-1,
{!XCurrent}))
If(({!Direction} = 2),{!YCurrent}+1, 
If(({!Direction} = 4),{!YCurrent}-1,
{!YCurrent}))

The purpose of these formulas is to take the Current value we are using in the flow and either increment or subtract from it or keep it the same. This will make moving around a map easily achievable and scalable to any sized map.

Updating The flow.

Connecting the Path

After the assignment, click on the plus sign and select the connect option. Now set the Get records; this will cause it to loop around to the get records.

Testing

To test this, click the debug option in the flow, and when this loads up, it should display the Description and the X and Y values at 1 with options to move south and east if you have followed along. You can play about by traversing the map when you have tried this out. You will be able to move on to the next step. We will pick up on this in the future. If you have followed the flow, it should look like the following flow.

Overview of flow and how it should look so far.

Next Steps

Now you have finished playing around with the game. You will notice playing through it that you picked up some items and visited a cave to go further in but could not access it. We will cover this in the next part, allowing us to finish this map. We will also be building functionality to move between maps which means we will be adding more elements and updating the criteria on existing elements.

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

Other Posts