Money and inventory

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Musick
Newbie
Posts: 22
Joined: Wed Jun 20, 2018 3:14 am
Contact:

Money and inventory

#1 Post by Musick » 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?

User avatar
Per K Grok
Regular
Posts: 169
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls
Projects: Defenders of Adacan
Deviantart: pekj
itch: per-k-grok
Location: Sverige
Contact:

Re: Money and inventory

#2 Post by Per K Grok » Sun Jul 08, 2018 1:21 pm

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.
Image Visual Story Telling, DeviantArt Group for animations, comics, games and illustrations https://www.deviantart.com/acgi

Musick
Newbie
Posts: 22
Joined: Wed Jun 20, 2018 3:14 am
Contact:

Re: Money and inventory

#3 Post by Musick » Mon Jul 09, 2018 5:00 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users