All right,
I have been spending lots of time
(*cough* days*cough* ) trying to figure out how to code an inventory with images instead of text and I came up with this:
(By the way, the text is long but the question is very simple)Code:
screen picture:
#the background with a pretty detailed frame
add "black_background.jpg"
add "frame.png"
#a sexy grid
grid 4 2:
spacing 28
xpos 330
ypos 113
#The items, those are images instead of text!!
imagebutton idle"001.png" hover "002.png" hovered Show("description") unhovered Hide("description") action Jump("itemmenu")
imagebutton idle"003.png" hover "003.png" hovered Show("description") unhovered Hide("description") action Jump("itemmenu")
imagebutton idle"007.png" hover "007.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"008.png" hover "008.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"009.png" hover "009.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"001.png" hover "002.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"012.png" hover "012.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
imagebutton idle"011.png" hover "011.png" hovered Show("description") unhovered Hide("description") action Show("itemmenu")
As you see, this is not the inventory system
per se but a representation of what I want the items to behave like:
>I want the inventory to have 8 items max
>When hover the imagebutton/item shows screen description
>When clicked they show a small screen menu with options like "Use", "Send them back to storage/Delete", "Return"(hide itemmenu).
Ok, so I have about 30 different obtainable items with different descriptions and uses...
I calculated two different solutions:
Use lots of IF statements:Something like:
Code:
if item 001:
imagebutton idle"001.png" hover "002.png" hovered Show("description") unhovered Hide("description") action Jump("start")
Except that if I don't have the item Ren'py goes "HURR DURR GRID ISN'T FULL" . Should I use "else"? Should I use vbox instead?
This might be the messiest and the longest path though...
Use listsThis is the best path I found and the one I'm working on.
However... Apparently
I can't python at all. I need help...
Let's start,
I create a list:
Code:
label start:
$ item= [] #The list is empty
Hmn... I guess I need to use classes since the items are not just text.
Then before the label start I put this code I snatched from
here:
Code:
init python:
class Item:
def __init__(self, name, cost, description, displayable):
self.name = name
self.cost = cost
self.description = description
self.displayable = displayable #image.png goes there, I hope this is possible
class Inventory: #I guess this is the money...
def __init__(self, money=10):
self.money = money
self.items = []
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
self.items.append(item)
return True
else:
return False
def earn(self, amount):
self.money += amount
def has_item(self, item):
if item in self.items:
return True
else:
return False
Then after the label start:
Code:
label start:
$ item= []
python:
inventory = Inventory() #HUN? What does this mean?
spaghetti = Item("Spaghetti", 3, "Spaghetti: This pasta is good for cooking", "00a.png")
olives = Item("Olives", 4, "Olives: They taste good. ", "00b.png")
chocolate = Item("Chocolate", 11, "Chocolate: A sweet milk chocolate tablet", "00c.png")
cabbage = ("Cabbage", 27, "Cabbage: Cabbages are healthy!", "00d.png")
#those are examples
Ok, ok, whatever, the biggest question is
HOW DO I DISPLAY THIS ON A SCREEN? I have to use "for" but how

? I think the code I want is similar to the one used to display the save/load screens:
Code:
# Display ten file slots, numbered 1 - 10.
for i in range(1, columns * rows + 1):
# Each file slot is a button.
button:
action FileAction(i)
xfill True
has hbox
# Add the screenshot.
add FileScreenshot(i)
# Format the description, and add it as text.
$ description = "% 2s. %s\n%s" % (
FileSlotName(i, columns * rows),
FileTime(i, empty=_("Empty Slot.")),
FileSaveName(i))
text description
key "save_delete" action FileDelete(i)
...What does (i) mean anyway?
Thanks for reading. Any help appreciated

!