Inventories - I need a walkthrough
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.
- mishila
- Newbie
- Posts: 8
- Joined: Sun Jul 12, 2009 2:28 am
- Projects: lament - an afterlife story
- Contact:
Inventories - I need a walkthrough
Hi.
I need help making an inventory for my game.
It requires you to pick up objects and you will be able to save them, and possibly use them, later on in the game.
Now before you redirect me to this and this, I've seen them. Frankly, I don't understand them, and I would be eternally grateful if someone could break it down for me - namely the first link.
How would I be able to replicate that same concept using screens?
How do I add multiple items to the inventory?
And... where do I define item_name? How would I show a picture of the item, also? Is there a way to show every item in the inventory at once, and once clicked on, they can be enlarged [think CG gallery].
I'm so ignorant. Even if you can just answer one of my questions, you will have helped me.
Thank you!
I need help making an inventory for my game.
It requires you to pick up objects and you will be able to save them, and possibly use them, later on in the game.
Now before you redirect me to this and this, I've seen them. Frankly, I don't understand them, and I would be eternally grateful if someone could break it down for me - namely the first link.
How would I be able to replicate that same concept using screens?
How do I add multiple items to the inventory?
And... where do I define item_name? How would I show a picture of the item, also? Is there a way to show every item in the inventory at once, and once clicked on, they can be enlarged [think CG gallery].
I'm so ignorant. Even if you can just answer one of my questions, you will have helped me.
Thank you!
- 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: Inventories - I need a walkthrough
I'm pretty new to Ren'py, but here's my interpretation of the code:
$ items.append("stone")
$ items.append("stone")
$ items.append("stone")
If you want to do it with a single line of code ($ items.my_append("stone", 3)), you need do define inventory as an object (second inventory example) and define a method/function for adding multiple items.
If you want the display grouped items ("Inventory: 3 stones, 2 chocolates"), you need to modify the code, that prepares the variable "inventory_show" in the for loop.
Instead of adding the item name to the text that will be display (inventory_show += item_name), just display the picture instead and delete all parts that prepare and display the text. You may need to handle x,y coordinates for the item images (something like x=i*100), based on item index(i).
Code: Select all
init python:
showitems = True # variable showitems is set here. This line must be before "if showitems:" line or there will be an error
#missing init of items! add the next line:
items = [] # this variable stores the items. Here we give it an empty value - a list with no elements. We need this or there will be an error, the first time we try to use this variable in our function
def display_items_overlay(): # we define a new function - the indented part
if showitems: # if showitems is False, nothing happens
inventory_show = "Inventory: " # inventory_show is a string variable. here we give it the initial value - the text "Inventory: ".
for i in range(0, len(items)): # this for loop repeats indented parts. variable "i" has a value 0 in the first repetition; "i" increases by 1 with every repetition, until "i" is equal to the number of items. Function len(items) returns the number of items.
item_name = items[i].title() # items[i] represents individual inventory items, where "i" is the items index - from 0 to the number of items.
"Items" is a variable/object of type list. Calling the title() function, returns the name of a list item, as a string - in our case - this is the name of inventory item. We store the name of the item (string) into variable "item_name".
if i > 0:
inventory_show += ", " # we add a comma to the string "inventory_show" for every repetition, except the first time
inventory_show += item_name # for every repetition, we add a string variable "item_name" (we stored it a few lines back), to the (also string) variable "inventory_show".
# this is outside the for loop. "inventory_show" should now contain the text we want to display - all inventory items listed with commas.
ui.frame() # draws a frame around the text
ui.text(inventory_show) # displays the text - inventory_show is the variable we prepared earlier.
config.overlay_functions.append(display_items_overlay) # this line ensures, we don't need to call the function we defined. Instead, we control whether inventory is shown or not by setting the value of showitems to False or True. Magic...
# end of python code; you use these lines to control the inventory in Ren'py code:
$ items.append("stone") #when you want to add items
$ items.remove("stone")#when you want to remove items
$ showitems = False #when you don't want to show the inventory onscreen (cutscenes and the like)
$ showitems = True #when you want to reshow the inventory after the cutscene is over
This code shows an information screen: http://www.renpy.org/wiki/renpy/doc/coo ... ion_ScreenHow would I be able to replicate that same concept using screens?
You use the same code to add the item multiple times. To add 3 stones:How do I add multiple items to the inventory?
$ items.append("stone")
$ items.append("stone")
$ items.append("stone")
If you want to do it with a single line of code ($ items.my_append("stone", 3)), you need do define inventory as an object (second inventory example) and define a method/function for adding multiple items.
If you want the display grouped items ("Inventory: 3 stones, 2 chocolates"), you need to modify the code, that prepares the variable "inventory_show" in the for loop.
Item name is a variable, internal to the function for inventory display. You don't need to define it, or use it, outside of this function. When you add the items with "append", the string you are appending will be used as item_name.And... where do I define item_name?
Replace the code in the for loop where "inventory_show" is being prepared.How would I show a picture of the item, also?
Instead of adding the item name to the text that will be display (inventory_show += item_name), just display the picture instead and delete all parts that prepare and display the text. You may need to handle x,y coordinates for the item images (something like x=i*100), based on item index(i).
Check out imagebuttons in the Information_Screen example.Is there a way to show every item in the inventory at once, and once clicked on, they can be enlarged [think CG gallery].
- mishila
- Newbie
- Posts: 8
- Joined: Sun Jul 12, 2009 2:28 am
- Projects: lament - an afterlife story
- Contact:
Re: Inventories - I need a walkthrough
Thank you for being so thorough! I will put this to good use - you have helped me immensely.
-
kenobihiro
- Newbie
- Posts: 16
- Joined: Thu Feb 23, 2012 1:36 pm
- Contact:
Re: Inventories - I need a walkthrough
leon wrote:I'm pretty new to Ren'py, but here's my interpretation of the code:
Code: Select all
init python: showitems = True # variable showitems is set here. This line must be before "if showitems:" line or there will be an error #missing init of items! add the next line: items = [] # this variable stores the items. Here we give it an empty value - a list with no elements. We need this or there will be an error, the first time we try to use this variable in our function def display_items_overlay(): # we define a new function - the indented part if showitems: # if showitems is False, nothing happens inventory_show = "Inventory: " # inventory_show is a string variable. here we give it the initial value - the text "Inventory: ". for i in range(0, len(items)): # this for loop repeats indented parts. variable "i" has a value 0 in the first repetition; "i" increases by 1 with every repetition, until "i" is equal to the number of items. Function len(items) returns the number of items. item_name = items[i].title() # items[i] represents individual inventory items, where "i" is the items index - from 0 to the number of items. "Items" is a variable/object of type list. Calling the title() function, returns the name of a list item, as a string - in our case - this is the name of inventory item. We store the name of the item (string) into variable "item_name". if i > 0: inventory_show += ", " # we add a comma to the string "inventory_show" for every repetition, except the first time inventory_show += item_name # for every repetition, we add a string variable "item_name" (we stored it a few lines back), to the (also string) variable "inventory_show". # this is outside the for loop. "inventory_show" should now contain the text we want to display - all inventory items listed with commas. ui.frame() # draws a frame around the text ui.text(inventory_show) # displays the text - inventory_show is the variable we prepared earlier. config.overlay_functions.append(display_items_overlay) # this line ensures, we don't need to call the function we defined. Instead, we control whether inventory is shown or not by setting the value of showitems to False or True. Magic... # end of python code; you use these lines to control the inventory in Ren'py code: $ items.append("stone") #when you want to add items $ items.remove("stone")#when you want to remove items $ showitems = False #when you don't want to show the inventory onscreen (cutscenes and the like) $ showitems = True #when you want to reshow the inventory after the cutscene is overThis code shows an information screen: http://www.renpy.org/wiki/renpy/doc/coo ... ion_ScreenHow would I be able to replicate that same concept using screens?
You use the same code to add the item multiple times. To add 3 stones:How do I add multiple items to the inventory?
$ items.append("stone")
$ items.append("stone")
$ items.append("stone")
If you want to do it with a single line of code ($ items.my_append("stone", 3)), you need do define inventory as an object (second inventory example) and define a method/function for adding multiple items.
If you want the display grouped items ("Inventory: 3 stones, 2 chocolates"), you need to modify the code, that prepares the variable "inventory_show" in the for loop.
Item name is a variable, internal to the function for inventory display. You don't need to define it, or use it, outside of this function. When you add the items with "append", the string you are appending will be used as item_name.And... where do I define item_name?
Replace the code in the for loop where "inventory_show" is being prepared.How would I show a picture of the item, also?
Instead of adding the item name to the text that will be display (inventory_show += item_name), just display the picture instead and delete all parts that prepare and display the text. You may need to handle x,y coordinates for the item images (something like x=i*100), based on item index(i).
Check out imagebuttons in the Information_Screen example.Is there a way to show every item in the inventory at once, and once clicked on, they can be enlarged [think CG gallery].
Thank very much for this post. Can i ask if there a way to interact with those item being displayed on-screen ( like a button to trigger an event)?
- 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: Inventories - I need a walkthrough
@kenobihiro: If you need to trigger events, you use imagebuttons to display the items. http://www.renpy.org/doc/html/screens.html#imagebutton
Who is online
Users browsing this forum: Bing [Bot], Google [Bot]



