Walkthrough on inventory system
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.
- lk09jh87gf65
- Newbie
- Posts: 8
- Joined: Wed Jan 08, 2014 5:04 pm
- Contact:
Walkthrough on inventory system
Hello, I've seen the codes for inventories but they confuse me quite a bit. I need a simplified way of understanding how to make it work. My game doesn't require anything really complicated, mostly single-use, combine item, and illustrations for the items in an inventory menu. No lifebar or anything like that. It's just seems like really complicated code.
Re: Walkthrough on inventory system
It's easy enough to make an inventory; just store the items in it as a list.
You can add items to it
and remove items from it
Of course, the player can't see any of that going on; so you need some kind of representation for them to see the items and interact with them. It's probably best to use screens to do this.
Let's set up a new screen that will show our inventory.
This screen puts a frame in the top left of the screen which will then show all out inventory items horizontally next to each other, assuming we've set up pictures for them (where if the inventory item is "hat" the pictures are called "hat_insensitive.png" "hat_idle.png" "hat_hover.png" etc, as here: http://www.renpy.org/doc/html/screens.html#imagebutton
Clicking on the picture jumps you to a label called hat, where you can do whatever it is you wanted to do with the hat. You show and hide the screen with show screen inv and hide screen inv.
This is only a very simplistic version, of course, but hopefully it gives you some idea of where to start. For a slightly more advanced version you can look up how to use Classes for the inventory and inventory items. This will allow things like
Code: Select all
$ inventory = []
Code: Select all
$ inventory.append("hat")
Code: Select all
$ inventory.remove("hat")
Let's set up a new screen that will show our inventory.
Code: Select all
screen inv:
frame:
xalign 0.0
yalign 0.0
hbox:
for i in inventory:
$ iname = i + "_%s.png"
imagebutton auto iname action Jump(i)
Clicking on the picture jumps you to a label called hat, where you can do whatever it is you wanted to do with the hat. You show and hide the screen with show screen inv and hide screen inv.
This is only a very simplistic version, of course, but hopefully it gives you some idea of where to start. For a slightly more advanced version you can look up how to use Classes for the inventory and inventory items. This will allow things like
Code: Select all
if "hat" in inventory:
- lk09jh87gf65
- Newbie
- Posts: 8
- Joined: Wed Jan 08, 2014 5:04 pm
- Contact:
Re: Walkthrough on inventory system
I'm sorry, but where do I enter these? I'm sure the last one is in the screens.rpy but where in the script(or otherwise) do the other ones go in. Also, don't I need like frame and inventory pictures for the inventory screen? Sorry, I'm very new to this.Showsni wrote:It's easy enough to make an inventory; just store the items in it as a list.
You can add items to itCode: Select all
$ inventory = []
and remove items from itCode: Select all
$ inventory.append("hat")
Of course, the player can't see any of that going on; so you need some kind of representation for them to see the items and interact with them. It's probably best to use screens to do this.Code: Select all
$ inventory.remove("hat")
Let's set up a new screen that will show our inventory.
This screen puts a frame in the top left of the screen which will then show all out inventory items horizontally next to each other, assuming we've set up pictures for them (where if the inventory item is "hat" the pictures are called "hat_insensitive.png" "hat_idle.png" "hat_hover.png" etc, as here: http://www.renpy.org/doc/html/screens.html#imagebuttonCode: Select all
screen inv: frame: xalign 0.0 yalign 0.0 hbox: for i in inventory: $ iname = i + "_%s.png" imagebutton auto iname action Jump(i)
Clicking on the picture jumps you to a label called hat, where you can do whatever it is you wanted to do with the hat. You show and hide the screen with show screen inv and hide screen inv.
This is only a very simplistic version, of course, but hopefully it gives you some idea of where to start. For a slightly more advanced version you can look up how to use Classes for the inventory and inventory items. This will allow things likeCode: Select all
if "hat" in inventory:
Re: Walkthrough on inventory system
I'd define the screens at the top; you can do it in screens.rpy, but it's actually fine to do it in any other script file as well. Defining the inventory list needs to be done immediately after the start label, and adding and removing things from an inventory come wherever you want to do it in a game. And for this example you would beed pictures, yes. If you use textbuttons instead you don't need pictures.
Here, I'll throw together something as an example:
Here, I'll throw together something as an example:
Who is online
Users browsing this forum: Bing [Bot]