Page 1 of 1

Money and inventory

Posted: Sun Jul 08, 2018 12:17 pm
by Musick
For my next game, i would like to add items you can buy and use to change the storyline. I saw Renpy games with had a inventory screen where you could see your money and the items you purchased during the game.

Two situations I think off in my planned next game (about a theater assistant).

1. You can enter a shop in the beginning, and buy some items that may help you later. For example a present to impress/charm someone; if you bought the wrong present, you'll get in trouble then.
2. You can buy a meal for a nonplayercharacter during the game, if you want. Later, you might need the help of that NPC, and he will ever give you a wrong or right hint depending if you offered him a meal earlier.

The money would be limited, so that you can't buy everything in the game and must make choices.
How do I do this? Does anyone even have some data I could use?

Re: Money and inventory

Posted: Sun Jul 08, 2018 1:21 pm
by Per K Grok
Musick wrote: Sun Jul 08, 2018 12:17 pm For my next game, i would like to add items you can buy and use to change the storyline. I saw Renpy games with had a inventory screen where you could see your money and the items you purchased during the game.

Two situations I think off in my planned next game (about a theater assistant).

1. You can enter a shop in the beginning, and buy some items that may help you later. For example a present to impress/charm someone; if you bought the wrong present, you'll get in trouble then.
2. You can buy a meal for a nonplayercharacter during the game, if you want. Later, you might need the help of that NPC, and he will ever give you a wrong or right hint depending if you offered him a meal earlier.

The money would be limited, so that you can't buy everything in the game and must make choices.
How do I do this? Does anyone even have some data I could use?
OK. There is a lot of stuff in this question.

You would need a variable to store the value of the money.

default Money = 5000

When the player buys something you reduce the price from Money.

$ Money -= 100


You will need some stuff to buy. Keeping it simple we use a True or False variable for that. If True the player have the item, if False the player does not.

default Item1 = False
default Item2 = False
default Item3 = False
default Item4 = False


The player goes into a shop. This activates a menu

Code: Select all

menu shop:
    "Do you want to buy something?"
    "Yes I want to buy item 1":
           $ Item1 = True
           $ Money -= 100
           jump afterBuy  #Label for the spot in the code you should go to after buying something
     "Yes I want to buy item 2":
           $ Item2 = True
           $ Money -= 100
           jump afterBuy   
       "Yes I want to buy item 3":
           $ Item3 = True
           $ Money -= 100
           jump afterBuy   
       "Yes I want to buy item 4":
           $ Item4 = True
           $ Money -= 100
           jump afterBuy  
       "No thank you" :
           jump afterBuy
To show what items the player have and how much money you need a screen. Write this in the screens.rpy

Code: Select all


screen inventory:
      if Item1:
           text "Item 1":
                  xpos 10
                  ypos 40

      if Item2:
           text "Item 2":
                  xpos 10
                  ypos 60
                  
 	if Item3:
 	    text "Item 3"
 	          xpos 10
                  ypos 80
                  
         if Item4:
 	    text "Item 4"
 	          xpos 10
                  ypos 100
                  
         text "Money left [Money] gold coins.":
             xpos 10
             ypos 120
To open the screen you write

show screen inventory

to hide it

hide screen inventory

In menu above you should put in a show screen after changing the variables so that the latest variables is what is shown.

Code: Select all

    "Yes I want to buy item 1":
           $ Item1 = True
           $ Money -= 100
           show screen inventory
           jump afterBuy 
Do this for all items.

This is of course very simplified. But I hope it gives you the basic idea of one way of doing this. Then you can add on stuff to make it more sophisticated. You will probably want to use lists to store items and prices.

Also, I have only written this done without any checking or testing so there might be mistakes in the text.

Re: Money and inventory

Posted: Mon Jul 09, 2018 5:00 am
by Musick
Thanky you, that is a very informative answer. As I am totally knew with Renpy, I'll take some time to get through that all, but I'll kep coming back to it.