Slots Demo
v1.0
This demo demonstrates the Deterministic Random system that comes with Juicy Actions. The three slots wheels use deterministic random by default, with different values that keep their keys different. But we can toggle the use of Deterministic Random on and off, to utilize the built-in randomizer if we'd like.
Deterministic RandomThe Scene

We have a simple slots game with three reels, a spin button, and an amount of cash in the bank ($1,000). The overlay holds fields for the global seed, and a seed for each reel, along with a button that toggles the use of Deterministic Random on and off.
Press play, and spin the reel. You may win, you may lose, but so long as Deterministic Random is true, you'll get the same spin results each time you press play.
Set the values of the reel seeds to be the same for each one. Then spin again, and each reel will have the same result.
Without changing the reel seed values, toggle off "Deterministic", and spin again β results will now be random.
The Code
SpinManager.cs is the main core of the demo. The method ToggleDeterministic() is called by the Deterministic button, and ensures that each reel sets its Random mode to either use or not use the Deterministic Random.
ReelManager has a DeterministicRandom field which is auto-assigned to a new DeterministicRandom with the seed value provided. While the seed starts as 0, it is set by SpinManager whenever the SpinRoutine() method is called, starting the reels spinning.
The SeedIncrement is what you can set in the game view, via the reel seed fields. The final seed for each reel is computed by adding the masterSeed to the value of spinCount multiplied by reelIncrement.
This way, we can change global results by updating masterSeed, or individual reel results by changing the individual SeedIncrement on the reel.
Each time we spin, we increment spinCount by +1, which means each spin will have a different final reelSeed, which we set on the reel prior to spinning or computing any end result values.
Reel Spins
Each real will spin for a random amount of time, with subsequent reels spinning longer than the previous ones.
Generating Random Target Symbol
From the available symbols, each reel determines the symbol it will end up at. The rest of the logic on actually spinning to end up on that reel is outside of the scope of this documentation, but you can definitely look at the code to see what's going on.
Random.Range in this context utilizes the public DeterministicRandom Random property, which means we can get a consistent value returned, based on the seed.
Other Juicy Actions Uses
There are ActionExecutors throughout the demo that are adding additional juice and logic to the demo game.
Spin Button
SpinButton, on the Spin Button UI object in the scene, has OnSpinActions which increment the amount of money the player has (it costs $10 to spin), and the "Spin Count" value. Both of these are saved on the global Action Blackboard.

It also has an Action Runner component, with a group that loops infinitely. The only action is one that pulses the color of the button between green and grey β importantly it ends the animation at grey, the "off" position.

This Action also has a Conditional attached to it. When the IsSpinning value is true, the action will not start β it only will start when the value is false, or missing from the Blackboard. This means once we start spinning, the action will not change the color, and the button will not pulse green.
Reels
Each Reel object also has an ActionExecutor onSpinActions attached to the ReelManager class. This has a group with a single action as well which plays an audio clip. The group is set to loop infinitely, though the action has a 0.1 second timeBeforeNextAction set in the Inspector, so the loop will happen 10 times per second.

The onSpinAction.Execute(this) call is made when the reel starts spinning, which starts the action loop. The SpinRoutine (a coroutine) in ReelManager.cs will then call StopAllActions() when the main spin phase has expired, which ends the repeting click sound populated in the Action.
Hopefully this demo scene helps to showcase the power of the Deterministic Random, and how you can use it in your project to take control over random interactions and logic.
Demo ScenesLast updated