As much as I'd love for my first post to not be a question, here it is:
I'm struggling with properly initialising lists and classes to build a data structure.
Trait is a custom class containing a name (for now)
Char is a custom class which should have a list of Trait (and other vars)
The only line in the start label is to find the name of the first trait on the Char prax.
I've been going around in circles for the past few hours, but cannot find anything to explain where I'm going wrong with this. Thanks for any help!
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 22, in script
"[prax.traits[0].name]"
AttributeError: Trait instance has no attribute 'name'
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 22, in script
"[prax.traits[0].name]"
File "E:\renpy-6.99.8-sdk\renpy\ast.py", line 603, in execute
renpy.exports.say(who, what, interact=self.interact)
File "E:\renpy-6.99.8-sdk\renpy\exports.py", line 1121, in say
who(what, interact=interact)
File "E:\renpy-6.99.8-sdk\renpy\character.py", line 819, in __call__
what = what_pattern.replace("[what]", sub(what, translate=translate))
File "E:\renpy-6.99.8-sdk\renpy\character.py", line 801, in sub
return renpy.substitutions.substitute(s, scope=scope, force=force, translate=translate)[0]
File "E:\renpy-6.99.8-sdk\renpy\substitutions.py", line 229, in substitute
s = formatter.vformat(s, (), kwargs)
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 563, in vformat
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 585, in _vformat
File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/string.py", line 652, in get_field
AttributeError: Trait instance has no attribute 'name'
Windows-8-6.2.9200
Ren'Py 6.99.8.959
test 0.0
Code: Select all
init python:
class Trait:
def __init__(self, name="Genius"):
self.name = name
class Char:
def __init__(self, name="unknown", age="unknown", traits="unknown"):
self.name = name
self.age = age
self.traits = traits
init:
$ prax = Char(
name = "Prax",
age = 35,
traits = [Trait()],
)
label start:
"[prax.traits[0].name]"