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?
Money and inventory
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.
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.
- Per K Grok
- Miko-Class Veteran
- Posts: 882
- Joined: Fri May 18, 2018 1:02 am
- Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
- itch: per-k-grok
- Location: Sverige
- Contact:
Re: Money and inventory
OK. There is a lot of stuff in this question.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?
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
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
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
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.
-
- Regular
- Posts: 62
- Joined: Wed Jun 20, 2018 3:14 am
- Completed: Ariane's Assistant Ariane Eldar's Rock Strip Quiz 1
- Deviantart: SteampunkGorgon
- itch: ritchierat
- Contact:
Re: Money and inventory
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.
Re: Money and inventory
Your idea for incorporating items into your game sounds intriguing! Here's a refined version of your implementation using Ren'Py:Per K Grok wrote: ↑Sun Jul 08, 2018 1:21 pmOK. There is a lot of stuff in this question.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, get 1 hour loans, 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?
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 menuTo show what items the player have and how much money you need a screen. Write this in the screens.rpyCode: 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 open the screen you writeCode: 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
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.
Do this for all items.Code: Select all
"Yes I want to buy item 1": $ Item1 = True $ Money -= 100 show screen inventory jump afterBuy
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.
First, let's establish some variables:
python
Копировать код
default money = 5000
default item1 = False
default item2 = False
default item3 = False
default item4 = False
Now, let's create the shop menu:
python
Копировать код
menu shop:
"Do you want to buy something?":
"Buy Item 1 for 100 gold coins":
$ item1 = True
$ money -= 100
jump after_buy
"Buy Item 2 for 100 gold coins":
$ item2 = True
$ money -= 100
jump after_buy
"Buy Item 3 for 100 gold coins":
$ item3 = True
$ money -= 100
jump after_buy
"Buy Item 4 for 100 gold coins":
$ item4 = True
$ money -= 100
jump after_buy
"No, thank you":
jump after_buy
Next, let's create a screen to display the player's inventory and remaining money:
python
Копировать код
screen inventory:
vbox:
if item1:
text "Item 1"
if item2:
text "Item 2"
if item3:
text "Item 3"
if item4:
text "Item 4"
text "Money left: [money] gold coins"
To show the inventory screen, use show screen inventory, and to hide it, use hide screen inventory.
Finally, make sure to show the inventory screen after each purchase:
python
Копировать код
"Buy Item 1 for 100 gold coins":
$ item1 = True
$ money -= 100
show screen inventory
jump after_buy
This basic implementation should get you started. As you develop your game further, you can expand upon this framework to add more complexity and depth to your item system. Good luck with your game development!
- m_from_space
- Eileen-Class Veteran
- Posts: 1057
- Joined: Sun Feb 21, 2021 3:36 am
- Contact:
Re: Money and inventory
Are you a stupid AI response? Please stop pulluting this forum and open threads from years ago!
Who is online
Users browsing this forum: Majestic-12 [Bot]