Inventory Screen
Forum rules
Do not post questions here!
This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Do not post questions here!
This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
- leon
- Miko-Class Veteran
- Posts: 554
- Joined: Sun Oct 09, 2011 11:15 pm
- Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
- Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
- Organization: Team ANARKY
- Contact:
Inventory Screen
While there are a couple of inventory examples in the cookbook already, they don't address using pictures for inventory items. So here's one that does that, completed with hover effects, tooltips and selectable items. The inventory system here is using classes, so you might want to check Money and Inventory Systems for more detailed explanation on how these work.
The code is taken from Time Labyrinth and simplified for this example. Feel free to use the code however you like (same goes for Time Labyrinth code).
The code is taken from Time Labyrinth and simplified for this example. Feel free to use the code however you like (same goes for Time Labyrinth code).
- Attachments
-
- Inventory.zip
- (1.1 MiB) Downloaded 7722 times
Last edited by leon on Sun Jul 26, 2015 3:53 pm, edited 1 time in total.
Re: Inventory Screen
Code: Select all
import renpy.store as store
import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
- RavenBelmont
- Regular
- Posts: 36
- Joined: Tue Jul 16, 2013 10:47 am
- Contact:
Re: Inventory Screen
You sir are a genius. Thank you for helping us so much! Please keep 'em coming!
- leon
- Miko-Class Veteran
- Posts: 554
- Joined: Sun Oct 09, 2011 11:15 pm
- Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
- Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
- Organization: Team ANARKY
- Contact:
Re: Inventory Screen
You are right. That most likely isn't needed. I was reading the documantation that's out of date.xela wrote:Why is this relevant outside of pure python module? All python from .rpy files is already being executed in store namespace or am I misunderstanding the issue?Code: Select all
import renpy.store as store import renpy.exports as renpy # we need this so Ren'Py properly handles rollback with classes
Re: Inventory Screen
Well, doesn't hurt either I was afraid I messed something up in my head again...leon wrote: You are right. That most likely isn't needed. I was reading the documantation that's out of date.
- Mole-chan
- Veteran
- Posts: 333
- Joined: Thu Aug 27, 2009 12:46 am
- Completed: DUAEL, Escape from Puzzlegate
- Projects: A Bird with Gold-Mended Wings
- Deviantart: mole-chan
- Skype: mole-chan
- itch: moleworks
- Contact:
Re: Inventory Screen
Thank you SO MUCH, this is exactly what I needed. 8'D I could probably do my own but this looks so much nicer.
- i1abnrk
- Regular
- Posts: 38
- Joined: Wed Nov 20, 2013 1:50 pm
- Projects: Critter Corral, Haremu Kikkemu Mo
- IRC Nick: i1abnrk
- Deviantart: i1abnrk
- Github: i1abnrk
- Location: Wisconsin
- Contact:
Re: Inventory Screen
This was an excellent study guide for learning how to code my own solution in renpy. You did a solid job of commenting the code and gave me a basis for early hack tests into writing my game. Kudos and thanks.
- TheOneAndOnly-K
- Regular
- Posts: 78
- Joined: Mon Apr 07, 2014 10:33 am
- Contact:
Re: Inventory Screen
I want something like this, but this is rather complex for my liking.
I don't want the wording, and the .zip files contents are confusing to find out what my game needs in particular, not what has already been decided.
What I'm aiming for is for it to act like a store/mall idea.
I don't want the wording, and the .zip files contents are confusing to find out what my game needs in particular, not what has already been decided.
What I'm aiming for is for it to act like a store/mall idea.
-
- Regular
- Posts: 30
- Joined: Tue Apr 08, 2014 10:34 pm
- Projects: Dance With Me? (A date sim)
- Location: NY
Re: Inventory Screen
I almost ripped my hair out trying to incorporate this into my game.
First I just wanted to delete the mp and element bits. When I tried it out, ren'py had a hissy fit about indentation mismatches, so I tried that, still kept happening. Eventually I just copied and pasted the entire thing and see if I could edit things bit by bit, but even with the full code, untouched, ren'py is telling me that "inventory" is not defined.
First I just wanted to delete the mp and element bits. When I tried it out, ren'py had a hissy fit about indentation mismatches, so I tried that, still kept happening. Eventually I just copied and pasted the entire thing and see if I could edit things bit by bit, but even with the full code, untouched, ren'py is telling me that "inventory" is not defined.
- leon
- Miko-Class Veteran
- Posts: 554
- Joined: Sun Oct 09, 2011 11:15 pm
- Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
- Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
- Organization: Team ANARKY
- Contact:
Re: Inventory Screen
You probably forgot to create the inventory object:
You need to create an inventory object after "label start:" and before using it. Check out the code in script.rpy just after label start.
Removing properties (like element and mp) is pretty straightforward. Indentation mismatch means you are either missing a space or have too many. Check out the line that the error message reports.
Code: Select all
inventory = Inventory()
Removing properties (like element and mp) is pretty straightforward. Indentation mismatch means you are either missing a space or have too many. Check out the line that the error message reports.
Re: Inventory Screen
Hey, im a little new to coding and ive been trying to use your code and I read the cookbook about the inventory system to figure it out myself but...
Is there any way i can put a variable on the items when you classify them? so when used it would trigger an event (just like if you add the attribute mp=40, it adds onto your mp.)
For instance:
a quest event where you need to retrieve a chocolate bar from a person. It goes into your inventory and If you try using it in the inventory you get a message saying " I can't use this here."
Then when you get to the person and use the chocolate bar you get the message "You gave the chocolate bar."
basically... is it possible to have an item trigger a certain event when used in the right time? then anywhere else in the game if its used its not thrown out/used/ basically inactive?
the things i tried:
Ive been trying to use if statements but im not sure if theres a 'global' if statement. Basically whenever it came across the if statement it would work but then once passed that statement further along in the story if i tried clicking the item again it would crash it.
please help!
Is there any way i can put a variable on the items when you classify them? so when used it would trigger an event (just like if you add the attribute mp=40, it adds onto your mp.)
For instance:
a quest event where you need to retrieve a chocolate bar from a person. It goes into your inventory and If you try using it in the inventory you get a message saying " I can't use this here."
Then when you get to the person and use the chocolate bar you get the message "You gave the chocolate bar."
basically... is it possible to have an item trigger a certain event when used in the right time? then anywhere else in the game if its used its not thrown out/used/ basically inactive?
the things i tried:
Ive been trying to use if statements but im not sure if theres a 'global' if statement. Basically whenever it came across the if statement it would work but then once passed that statement further along in the story if i tried clicking the item again it would crash it.
please help!
- leon
- Miko-Class Veteran
- Posts: 554
- Joined: Sun Oct 09, 2011 11:15 pm
- Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
- Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
- Organization: Team ANARKY
- Contact:
Re: Inventory Screen
Sorry for the late reply. Change the item's use method like this:
And then add the event like this.
I got this message in PM. I'll reply here in case anyone else may need this.
When defining the items, set the parameter recipeItem to True like this:
And make all items selectable:
Add a button that will handle combining the items to inventory_screen:
Add the function to combine the items somewhere:
Finally add some recipes somewhere after the item definitions:
Code: Select all
def use(self):
if self.name=="Chocolate":
renpy.call_in_new_context("chocolate_event")
Code: Select all
label chocolate_event:
if renpy.showing("sprite_name"):
"You gave the chocolate bar."
$inventory.drop(chocolate)
else:
"I can't use this here."
return
First change the Item class like this:Roxie wrote:Hello Leon!
I wanted to thank you for sharing the inventory screen code in the Renpy Cookbook. It really helped me better understand classes as well. I was wondering if you could give me some programming advice to add inventory features. I was hoping to be able to combine items, break them apart to more items, and to use the item with a scene or person, aka make a VN style adventure game. For the Item class, I have element (items released) and recipe (items needed) to the items able to be taken apart or combined. How would I allow up to two items in the inventory to be selected at the same time? Would I need to make another class that can only hold two items and use methods to affect that class only? I guess that brings up the issue on how do I clear items from both lists after two items merge to one. Or is there a way to do it all under the Inventory class? Classes are a hit and miss for me as you can tell
Here's a visual image http://altabestudio.com/wp-content/gall ... entory.png
I wanted the selected items to appear in the bottom two boxes which would involve another screen is my guess.
Thanks for reading!
- Roxie
Code: Select all
class Item(store.object):
def __init__(self, name, player=None, hp=0, mp=0, element="", image="", cost=0, recipeItem=False):
self.selected=False
self.recipeItem=recipeItem
#...
def use(self): #here we define what should happen when we use the item
if self.recipeItem:
self.selected=not self.selected
#...
When defining the items, set the parameter recipeItem to True like this:
Code: Select all
banana = Item("Banana", mp=20, image="gui/inv_banana.png", recipeItem=True)
Code: Select all
Also change the imagebutton for the item in inventory_screen like this:
if item.recipeItem:
imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), SetVariable("item", item), item_use] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
else:
imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), Show("inventory_button"), SetVariable("item", item), Hide("inventory_screen"), item_use] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
Code: Select all
if item.selected:
add "gui/selected.png" xpos x ypos y anchor(.5,.5)
Add a button that will handle combining the items to inventory_screen:
Code: Select all
textbutton "Combine" action [Function(combine_items), Hide("inventory_screen"), Show("inventory_button")] align (.80,.80)
Add the function to combine the items somewhere:
Code: Select all
init python:
def combine_items():
for item in inventory.items:
for recipe in recipes:
recipe_tmp = recipe
if item in recipe and item.selected:
recipe_tmp.remove(item)
if len(recipe_tmp)==1:
for tmp_item in recipe:
pass
inventory.drop(item)
inventory.add(recipe[0])
return
Code: Select all
recipes = []
recipes.append([meat_with_condiment, stewed_meat, yellow_petals])
recipes.append([chocolate_gun, chocolate, gun])
Re: Inventory Screen
wow, this is fantastic! thank you very much for sharing those codes!
i got a question, im want make a game like phoenix wrigth games, and i need know one thing:
in those games, when you click one item, shows you another image with a long description
for example:
you click " match box", then shows another image of the item and a longer description about that item.
¿how can i do that in this code?
and
¿how can i make a special option, like .. if X item is in the inventory: X option will be showed?
thank you very much, i hope dont be a bother to you with thes questions.
i hope you a happry 2015
i got a question, im want make a game like phoenix wrigth games, and i need know one thing:
in those games, when you click one item, shows you another image with a long description
for example:
you click " match box", then shows another image of the item and a longer description about that item.
¿how can i do that in this code?
and
¿how can i make a special option, like .. if X item is in the inventory: X option will be showed?
thank you very much, i hope dont be a bother to you with thes questions.
i hope you a happry 2015
- leon
- Miko-Class Veteran
- Posts: 554
- Joined: Sun Oct 09, 2011 11:15 pm
- Completed: Visual Novel Tycoon, Night at the Hospital, Time Labyrinth, The Buried Moon, Left of Center, Super Otome Quest
- Projects: Lemon Project, Porcelain Heart, Dream's Dénouement
- Organization: Team ANARKY
- Contact:
Re: Inventory Screen
Create a screen like this:
And change the imagebutton in inventory_screen to call it:
Code: Select all
screen inventory_zoom(item):
if item.name=="Chocolate":
add "gui/inv_chocolate.png"
#...
textbutton "Back" action Return
Code: Select all
imagebutton idle pic hover pic xpos x ypos y action [Hide("gui_tooltip"), SetVariable("item", item), Hide("inventory_screen"), Show("inventory_button"), Show("inventory_zoom", item=item)] hovered [ Play ("sound", "sfx/click.wav"), Show("gui_tooltip", my_picture=my_tooltip, my_tt_ypos=693) ] unhovered [Hide("gui_tooltip")] at inv_eff
momotaros wrote:¿how can i make a special option, like .. if X item is in the inventory: X option will be showed?
Code: Select all
menu:
"Do nothing.":
"..."
"Give chocolate." if chocolate in inventory.items:
"You gave the chocolate away. :("
$inventory.drop(chocolate)
Re: Inventory Screen
you are awesome! thank you very much
Who is online
Users browsing this forum: No registered users