Learn how you can create a slot machine game in your domain.
This tutorial details how to create a slot machine game that pays out HFC in High Fidelity.
Here is how your slot machine game might play when you complete this tutorial:
To create this content, you'll need:
Consider familiarizing yourself with the following concepts:
Start by opening Interface in Desktop mode and connecting to your domain!
First, create a Slot Machine entity in your domain. You can use a Slot Machine entity that already exists:
You should now see a slot machine entity in your domain. This example entity consists of:
In our slot machine example, players will pay you (the domain owner) 1 HFC to start playing. The slot machine will pay out 25 HFC if the payer wins.
You will now learn how to pre-authorize the first payout of 25 HFC.
You'll need to put the "Authorization ID" and "Coupon ID" secrets into some sort of database. Here's why:
You're going to write an Assignment Client script (AC script) for the Slot Machine game logic, including payout logic. When the Slot Machine pays out, it needs to know the Authorization IDs and Coupon IDs associated with your pre-authorized payout funds.
There are many ways that the AC script can know these secrets. In this example, we will use a Google Sheet to store the data, and a Google Script to access the data in the Sheet.
var SPREADSHEET_IDto match the Spreadsheet ID of your spreadsheet above.
Make sure you keep the web app URL and the Google Sheet URL private, or your authorization data will be visible to anyone with access to the sheet!
You'll need to provide your users with a way to add slot machine play credits. Do this by adding an Entity Script to the Slot Machine entity.
First, we need to write the entity script. This script will do the following:
Click here to download a pre-made "Add Credits" entity script. Follow along with the comments in the code to understand what it's doing!
All users who load the Add Credits entities will be individually running this script as if it were an Interface script.
Next, add the entity script to the Slot Machine. If you're using the example Slot Machine entity provided, add the script to two parts of the entity to make it easier for players to add credits:
DESTINATION_USERNAMEto your username in
addCreditsButton.jsscript to your domain's ATP server. In Interface, go to Edit > Asset Browser > Choose File. Right-click the script file, then click "Copy URL".
You'll need to provide your users with a way to start the slot machine's reels.
First, write an entity script to put on the slot machine's Spin Lever. This script will send a message to an Assignment Client (AC) script that we'll write in a later step. This message will kick off the rest of the game logic.
Click here to download a pre-made "Spin Lever" entity script. Follow along with the comments in the code to understand what it's doing!
All users who load the Spin Lever entity will be individually running this script as if it were an Interface script.
Next, add the entity script from above to the "Spin Lever" entity.
slotMachineSpinLever.jsscript to your domain's ATP server. In Interface, go to Edit > Asset Browser > Choose File. Right-click the script file, then click "Copy URL".
You'll have to get a High Fidelity authentication token that has the
commerce_ro scope. You'll use this token when writing an Assignment Client (AC) script. This AC script checks your Recent Economic Activity for recent transactions of 1 HFC made in your domain with a specific memo ("1 Slot Machine Play Credit").
To get this auth token:
Next, you'll have to write an AC Script that will handle the slot machine game logic, including:
Click here to download a pre-made "Slot Machine" entity server script. This script is quite long and is arguably the most important element of this project! Follow along with the comments in the code to understand what it's doing.
To run the AC script on your domain from ATP:
HIFI_COMMERCE_TOKENto your HiFi
SLOT_MACHINE_REEL_1_IDto the Entity ID of the leftmost slot machine reel.
SLOT_MACHINE_REEL_2_IDto the Entity ID of the middle slot machine reel.
SLOT_MACHINE_REEL_3_IDto the Entity ID of the rightmost slot machine reel.
SLOT_MACHINE_PLAY_TEXT_IDto the Entity ID of the "Play Text" text entity right below the slot machine reels.
GOOGLE_SHEET_AUTH_SCRIPTto the URL of the Google Script Web App created earlier.
SLOT_MACHINE_AREAto the coordinates around which the slot machine entity will be placed. See the comments in the code for more details about why this is necessary.
slotMachineACScript.jsscript to your domain's ATP server. In Interface, go to Edit > Asset Browser > Choose File. Right-click the script file, then click "Copy URL".
+button on the right column
You're done! You should now have a basic but fully working slot machine in your domain, that you and anyone else in your domain can play.
Here are a few ideas for extending the basic functionality of this slot machine:
In this example, a user could change the colors of the unlocked reels to match just before the game ends, and thus force a payout. This example does not cover anti-cheat or anti-tampering methods for securing your slot machine or funds!