Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Random number and Inventory How-To

A topic by greendad37 created Sep 09, 2021 Views: 112
Viewing posts 1 to 1

In one of the games that I started on I have a simple card playing scenario to win or lose money in a casino. It is based on a random number comparison; if you "win" you get money added, and if you lose, you have money subtracted. Below is a sample code using Ramus scripting:

#test gte(Math.random(), .6);
#iftrue {{inline(inventory.money =+5)}}
#do localStorage.setItem("_inventory", JSON.stringify(inventory));

In this example, if the random number is greater than .6 you get $5 added to your money.  This assumes you've set up an inventory array at the beginning of the game.  Since there isn't auto-saving variables like Squiffy does, I periodically save to localStorage.

 Additional conditions can be coded such as checking to see if you've visited the casino multiple times (the Dead Leaves example has a test to see if you've tried something 5 times before) or if you've already won a preset casino "house limit."

I look forward to seeing how others have used some of the new Ramus features to code different scenarios.