I've been setting up a quite complicated game using NVL style dialogue and I've gotten nearly everything I want working, but I've been hung up on one thing for an entire week, and though I've been studying Python tutorials and help forums, I can't quite find the information to do what I want, especially as it relates to Ren'Py.
Basically, the game is going to have a LOT of clothing items for the player to wear, and each clothing item has attributes I want to be able to easily call in the dialogue script. As you can see from the Clothing custom class code below, those are the clothing's name, a description of it, a list of aspects (since the word 'properties' is reserved), the location on the player's body the item is worn, and the amount of the clothing item the player current possesses.
Now, I could easily just do the normal [raincoat.name] or [raincoat.description] in the Ren'Py script to display these attributes, but I want the player to be able to equip clothing into different 'slots', and I want to be able to separate out my logic, so I can call a method when the player equips an item, and everywhere else in the script just use the equipment slot variables - so [head_slot_name] or [head_slot_descrip] for example.
My game code is obviously a lot more than what I'm posting here, but these are all the relevant parts pulled out and presented. I have a .rpy file where I declare all my variables as defaults, and I have another .rpy file with my custom classes and their methods in a Python block. Then I have my .rpy file with the game script.
What I have below is a test to see if what I am trying even WORKS - the final equip method would obviously be more complicated with more equipment slots than just the head, and would ideally use the 'location' attribute in the Clothing class instances to assign the provided method argument into the proper location slot variables.
The code below doesn't produce any errors - the equip method just seems to do . . . nothing.
Code: Select all
default raincoat = Clothing("raincoat", "a slick yellow raincoat", ["waterproof"], "head", 1)
default head_slot_descrip = ""
default head_slot_name = ""
default player_inventory = Inventory("player")
init python:
import renpy.store as store
class Clothing(store.object):
def __init__(self, name, description, aspects, location, amount = 1):
self.name = name
self.description = description
self.aspects = []
self.location = []
self.amount = amount
class Inventory(store.object):
def __init__(self, name):
self.name = name
def equip(self, clothing_item):
head_slot_name = getattr(clothing_item, 'name')
head_slot_descrip = getattr(clothing_item, 'description')
label start:
$ player_inventory.equip(raincoat)
"The thing on your head slot is [head_slot_name]. It is [head_slot_descrip]."
Code: Select all
The thing on your head slot is . It is .
I'm pretty frustrated. All the rest of my very customized game code and screens and menus are working great, and this is one of the last stumbling blocks to putting everything together.
Like I said, my Python skills are fairly weak - but I've done everything else with self study - some things I consider much more complicated than this in Python, and somehow getting an instance to change a variable using a method call is proving impossible for me.
Any help appreciated, including 'Dude, it would be so much easier to do what you want if you do x,y,z instead . . ."