Hi guys, once again I'm back with more question as somewhat renpy noob.
As the title says, how do I pick a specific item in the list?
Here's the simplified version of my code:
I set up other button to change pages so don't worry about it. The problem is the "for backpack[0] in backpack" doesn't work as I expected. It crashes the game, but somehow "$ backpack.append(all_item[0])" works
. Since the items are going to be added to the backpack in random order, how can I pick each item in order and put them in different page of the backpack_display?
Also, since I haven't got the first part to be working, I'm not sure if the game will crash when there's not enough item in the backpack to fill the space on the display screen.
Thank you very much.
As the title says, how do I pick a specific item in the list?
Here's the simplified version of my code:
Python:
init python:
class item:
def __init__(self, name, image):
self.name = "{}".format(name)
self.image = "images/{}.png".format(image)
default all_item = [item("Apple", "apple"), item("Orange", "orange")]
default backpack = []
default page = 1
# Basic set up for the item class
label AA_test: # Get the game running
scene black
$ backpack.append(all_item[0])
$ backpack.append(all_item[0])
$ backpack.append(all_item[1])
$ backpack.append(all_item[1])
$ backpack.append(all_item[1])
# Get items
$ d = 1
show screen backpack_display
while d > 0:
"testing"
screen backpack_display:
if page == 1:
hbox:
xalign 0.5
yalign 0.5
for backpack[0] in backpack: # The 1st item in backpack
frame:
imagebutton:
idle item.image
action SetVariable ("Something", "not important")
for backpack[1] in backpack: # The 2nd item in backpack
frame:
imagebutton:
idle item.image
action SetVariable ("Something", "not important")
for backpack[2] in backpack: # The 3rd item in backpack
frame:
imagebutton:
idle item.image
action SetVariable ("Something", "not important")
elif page == 2:
hbox:
xalign 0.5
yalign 0.5
for backpack[3] in backpack: # The 4th item in backpack
frame:
imagebutton:
idle item.image
action SetVariable ("Something", "not important")
for backpack[4] in backpack: #The 5th item in backpack
frame:
imagebutton:
idle item.image
action SetVariable ("Something", "not important")
for backpack[5] in backpack: # The 6th item in backpack
frame:
imagebutton:
idle item.image
action SetVariable ("Something", "not important")
Also, since I haven't got the first part to be working, I'm not sure if the game will crash when there's not enough item in the backpack to fill the space on the display screen.
Thank you very much.