Mini-games

Simple Store Script For Ren’Py Games

June 13, 2024

Many visual novel developers would like to have a simple store system in their game for their players to buy items with their hard earned coins. That’s why I developed a simple store script with items in a grid layout that you can use in your games! This script is available for my patrons over at Patreon.com.

In the example project I made for this script, I’ve only got two categories, but you could add as many as you like. As you can see in the preview video above, the player can see how many coins they have in the bottom right corner. When they press the buy button for an item, the coins will be subtracted and the sum will be updated.

The code uses a nested dictionary for setting up the items and categories. In the example project, it looks like this:

default shop_items = {
    "fruits" : {
        "apple" : {"stock" : 10, "price" : 10},
        "lemon" : {"stock" : 5, "price" : 10},
        "banana" : {"stock" : 20, "price" : 35},
        "orange" : {"stock" : 3, "price" : 25},
        "pear" : {"stock" : 2, "price" : 15}
        },
    "vegetables" :
        {"carrot" : {"stock" : 33, "price" : 5},
        "cucumber" : {"stock" : 5, "price" : 2},
        "spinach" : {"stock" : 8, "price" : 6},
        "tomato" : {"stock" : 9, "price" : 15},
        "onion" : {"stock" : 25, "price" : 7}
        }
}

As you can see, the first item in the dictionary is another dictionary with the key “fruits”, which is one of the categories. The items for this key is then the actual store items for that category. Each item (apple, lemon etc.) contain it’s own dictionary that lists the details of each item, like how many are in stock and the price. With this, you can easily organize the shop items with different categories.

The rest of the script then contains code that uses this dictionary to lay out each item according to their category.

The script comes with many handy functions you can call to manage your store. These are functions like, adding a new item, removing an item, updating an items price if it changes at some point in the game, changing stock amount and more. Here’s an example of the “add_item_to_shop” function:

add_item_to_shop(name = "mango", category = "fruits", stock = 5, price = 10)

As you can see, it’s pretty straight forward to use! 😊

The post for this script has some documentation you can read to learn more, and the code has been commented as well. If you’re interested, you can follow the link below to get to the script on Patreon!

    Leave a Reply