What is the easiest way or the best way to make an 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.
What is the easiest way or the best way to make an inventory?
Like the tittle says I want to make an inventory, i kinda think of an array but i'm kinda lost on how to link it with a visual interface.
- Milkymalk
- Miko-Class Veteran
- Posts: 753
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: What is the easiest way or the best way to make an inventory?
Maybe I should continue my cookbook tutorial and actually do the example how to make an actual screen for the inventory. This has been asked a few times now.
Super-simple inventory:
Make a list in python (using "$ inventory = []" or without "$" if inside a python block) and add strings with inventory.append("ball"). Access the inventory with inventory[placenumber] and delete items with inventory.pop[placenumber].
To display the contents, you make a for-loop inside a screen that iterates through your inventory:
An a little more complex system:
viewtopic.php?f=51&t=44730
Super-simple inventory:
Make a list in python (using "$ inventory = []" or without "$" if inside a python block) and add strings with inventory.append("ball"). Access the inventory with inventory[placenumber] and delete items with inventory.pop[placenumber].
To display the contents, you make a for-loop inside a screen that iterates through your inventory:
Code: Select all
screen invscreen():
vbox:
for i in inventory:
text i
viewtopic.php?f=51&t=44730
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Re: What is the easiest way or the best way to make an inventory?
Yeah, you should, it is kinda complicated how to make visual interfaces with renpy, like there is really not much info about it, mostly about inventory interfaces, like i want to make my items to be displayed visually in the inventory and all that but i just don't really know how.Milkymalk wrote: ↑Thu May 24, 2018 7:21 pm Maybe I should continue my cookbook tutorial and actually do the example how to make an actual screen for the inventory. This has been asked a few times now.
Super-simple inventory:
Make a list in python (using "$ inventory = []" or without "$" if inside a python block) and add strings with inventory.append("ball"). Access the inventory with inventory[placenumber] and delete items with inventory.pop[placenumber].
To display the contents, you make a for-loop inside a screen that iterates through your inventory:An a little more complex system:Code: Select all
screen invscreen(): vbox: for i in inventory: text i
viewtopic.php?f=51&t=44730
- Milkymalk
- Miko-Class Veteran
- Posts: 753
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: What is the easiest way or the best way to make an inventory?
Visual display is a little more complicated, but not much. I can give you some pointers so you know where to look. You will understand Ren'Py much better after you have done this
It doesn't hurt to read the tutorial I linked. It explains how classes, methods and lists work.
If you want to make any kind of custom display, you need Screen Language: https://www.renpy.org/doc/html/screens.html This is in a way the "HTML" of Ren'Py (it mostly tells the game how a screen should look), but you can partially use Python inside it for dynamic screens.
Understand how for-loops work: https://wiki.python.org/moin/ForLoop They work just like that inside screens. My screen example just before is a for-loop that displays each element inside the list (with errors if it's not a string). "vbox" means "vertical box" and makes all elements appear in a column. Without it, each name would be written over the last one and it turns into a unreadable mess.
You can use "add" (displays images in screens) with dynamic image names:
So you either want to use the name of the item itself as a filename, or store a filename that will be used for this with each item in a class.
It doesn't hurt to read the tutorial I linked. It explains how classes, methods and lists work.
If you want to make any kind of custom display, you need Screen Language: https://www.renpy.org/doc/html/screens.html This is in a way the "HTML" of Ren'Py (it mostly tells the game how a screen should look), but you can partially use Python inside it for dynamic screens.
Understand how for-loops work: https://wiki.python.org/moin/ForLoop They work just like that inside screens. My screen example just before is a for-loop that displays each element inside the list (with errors if it's not a string). "vbox" means "vertical box" and makes all elements appear in a column. Without it, each name would be written over the last one and it turns into a unreadable mess.
You can use "add" (displays images in screens) with dynamic image names:
Code: Select all
add "images/items/"+itemname+".png"
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Re: What is the easiest way or the best way to make an inventory?
I did checked your tutorial, it is good, i do know though how classes,methods and lists work, i just have trouble on how to actually make that in a visual mannerso i can display it for the player.
- Milkymalk
- Miko-Class Veteran
- Posts: 753
- Joined: Wed Nov 23, 2011 5:30 pm
- Completed: Don't Look (AGS game)
- Projects: KANPEKI! ★Perfect Play★
- Organization: Crappy White Wings
- Location: Germany
- Contact:
Re: What is the easiest way or the best way to make an inventory?
Thanks
You will need screens for so many things that it's worth reading their docs thoroughly. But I can give you a barebones screen that you can modify to your needs:
This code expects inventory to contain elements of a class that has "name" and "filename" as fields:
You will need screens for so many things that it's worth reading their docs thoroughly. But I can give you a barebones screen that you can modify to your needs:
Code: Select all
screen show_inventory():
modal True # <- this screen prevents lower screens from taking input
fixed:
xpos 100 # <- adjust these to where you want your inventory
ypos 100
xsize 300
ysize 500
frame:
padding 10 # <- how many pixels between borders and content?
background "images/inventorybackground.png" # <- whatever you want as a background image
for i, item in inventory.enumerate(): # <- creates tuples of (number, item)
add "images/items/"+item.filename+".png" xpos (i%5)*50 ypos (i//5)*80 # <- displays images every 50 pixels with 5 images per row
text item.name xpos (i%5)*50 ypos (i//5)*75+5 # <- displays each item's name below
imagebutton idle "images/close.png" action Return() # <- closes the "call"ed screen
# to display the screen:
label blah:
call screen show_inventory()
Code: Select all
class Item(object):
__init__(self, name, filename):
self.name = name
self.filename = filename
inventory = []
inventory.append(Item('a ball', 'yellow_ball')
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Re: What is the easiest way or the best way to make an inventory?
check this simple...Python Tutorial
Who is online
Users browsing this forum: No registered users