The RPG Series
RPGs are one of gaming’s most popular and longest-lived genres, and some of the most popular series in the world have had entries (or even got their start) on the Game Boy. And now, thanks to GB Studio, it’s your turn to create an RPG of your own!
In this series, we will cover how to use GB Studio’s built-in events to create a basic RPG system that you can expand on for your own game. All project files will be available to download at the end of the article, and inside, you’ll have all the examples and assets we use in each article (along with some additional comments). You can use these as a reference or even expand on them to create your own game.
Quest 3-2: The Shop
Yawn! Wow, even though our inn didn’t have any beds, it looks like we slept for quite a while. Now that we’re all rested up, let’s head over to the shop and spend some of our hard-earned gold.
Creating a Shop
We already created our shop scene in a previous tutorial, but let’s populate it with some actors. We’ll start with some basic items (a Potion, a Mana Potion and Medicine), a Shopkeeper, an interaction point for that Shopkeeper (just like we did for the inn) and an NPC.

Readers familiar with GB Studio may have noticed something odd about the Item actors: the visible portion of each sprite is above the bottom row of tiles. We alluded to this in the previous article with the innkeeper, but to avoid having to use secondary actors to create interaction points for objects behind the counter, we used the built-in Sprite Editor to extend the canvas and adjust the actor’s image position relative to its collision area.

To see what we’ve changed, navigate to View > Sprites in GB Studio. By adjusting values in the fields on the right side of the editor, we expanded the canvas height from 16 px to 24 px and moved the sprite tiles to the top of the canvas. Then we resized the collision area in the bottom tiles to 8×16 px.


Now, the player will be able to interact with this sprite by walking up to the counter, because the invisible collision box extends to the lower edge of the counter.
Buying an Item
Next, let’s set up a simple script for a transaction. Just like we did with the Inn in the previous article, we’ll begin by setting a price for each item. In each item’s On Init script, we’ll rename the $Local 0 variable to “Price” and set a cost for each item.

In the On Interact script, we’ll start with some dialogue to explain the item. Since our $Price variable tracks the item’s price, we can also refer to it in the dialogue event by typing a $ symbol followed by the variable name (e.g., $Price). This will be replaced with the variable’s value when the script runs.

After the dialogue, we’ll use a [Compare Variable to Variable] event to check if the player has enough gold for the purchase. If they don’t, we’ll let them know. If they do, we’ll ask whether they want to purchase this item with a [Multiple Choice] event.

If the player decides to buy the item and has the funds, we’ll need to make sure they have room in their bag to carry it! To do this, we’ll create a cascading series of checks to see if the Item variable is empty, just like when we received an item as a reward from battle.

We’ll set the item type to 1, since that’s what we assigned to represent a Potion, and then we’ll fill that item slot with the assigned item in the first slot that’s free.
But what if we don’t have any room? We don’t want to pay for something we can’t carry, so in the final Else statement of our script, we’ll add another variable that we can check.

If the player’s bag is full, we’ll let them know with some dialogue and set a local variable (I’ve renamed it “Full Bag” here) to True. Then, after our bag script, we’ll check if $Full Bag is false.

If it’s false, that means a bag slot is free, and the item was successfully assigned to it. So we’ll deduct the gold via an [Evaluate Math Expression] event and thank the player for their purchase with additional dialogue. I’ve also used a local variable to mark that the item has been purchased, and then we’ll deactivate the actor.
If “Full Bag” is true, the player has already seen the warning message. So in the Else statement here, we’ll want to reset the $Full Bag variable so that the next time we interact with the actor, we don’t get stuck with a “full bag” even after freeing up space.
Restocking Limited Inventory
Deactivating the actor after successfully purchasing the item means that we can only interact with this once. To prevent our item from reappearing when the player reenters the shop, we can check whether the Purchased variable is true in its On Init scripts and deactivate it if so.

But what if we want to have the items restocked? We can’t make it through the whole game with just a single potion! To do this, we’ll leverage the Inn we created in our last lesson and implement a basic day-tracking system.
Create a new global variable called $Day. In the On Init script we just made for the actor, add a new [Compare variable with variable] event. The first variable we want to track is a local variable for the actor (if following the guide, this is Local 4). Name it $Internal Clock.
If $Internal Clock doesn’t match the value stored in $Day, we’ll reset its $Purchased variable to False and update its clock to match $Day.

Back in our Inn scene, let’s add a new event to the Inn actor to also increment the Day variable to progress time.

Now, time will progress in your game every time you sleep at an inn!
Showing a Wallet
To wrap up our Shop, let’s add a visual display of the player’s gold whenever they’re in the shop. In the top-right corner, our Shop scene has a small set of tiles, just like our Battle scenes.

Just like with our Battle scene, we’ll be using the [Replace Tile At Position] event to change these tiles based on the player’s global variables. But this time, instead of creating this script in the scene, let’s start using Custom Scripts so that we can easily call this event in each item and shop.
In the left navigation, find the Scripts section and click the + icon to create a new custom script. We’ll call this “Update Wallet”.

In this script, we’ll change the tile at each increment of wallet size, starting with the thousands column. Create a [Compare Variable with Value] event to see if our global $Gold variable is greater than 999. Inside, just like updating HP during battle, we’ll change a tile based on the value of a temporary variable. However, you’ll notice that Custom Scripts can only access global variables directly. Since Temp 0 isn’t available to select, we’ll use one of the placeholder variables – in this case, Variable A.

We’ll set Variable A to our $Gold variable so that we don’t accidentally change the player’s gold with our Math, and then divide it by 1,000 to get our thousands column number. Then we’ll replace the tile in the thousands column with the tile that matches our result from the numbers tileset.
Once you’ve created this script, do the same for each increment of your wallet size (hundreds, tens and ones).

If you need a refresher for how this math works, you can review how we used the modulus effects when updating the HUD for our Battle scene.
Now that we created a custom script, we can access it whenever we want to update the display of our player’s gold value while they’re shopping. For this scene, let’s place this in the On Init tab, so it always shows when we enter the shop. We do this with the [Call Script] event.
When we use the [Call Script] event, we’ll select our “Update Wallet” script, and since we’re using a Placeholder Variable, we’ll need to select a variable for it to access. For this, let’s select Temp 0.

Once we have that set up, let’s also add one to our item’s purchase script. When we successfully buy an item, we’ll update the display to see the cost deducted from our gold.

Now, the player can easily see how much gold they have on hand while they shop!
Next Quest:
Our wallets are hurting, but our bag is full. What’s left for an adventurer to worry about? Oh, right, quests! Next time, we’ll give the player their first real objective and learn how to track its progress.
You can download the project files here, and don’t forget to visit the project page on itch.io to ask questions or provide feedback. See you next time!
This article is part of a series: Let's Build an RPG!

Friendly Neighborhood Game Designer, Podcaster, and (ex)Librarian (he/him)
GB Studio Games | Tabletop Games





