Re: Adding Stats to Characters ... easily
Posted: Sat Nov 10, 2018 7:46 pm
Friends i am very new to Ren'py, what would i need to add to my script.rpy to include the separate stats file above in 1st post
Supporting creators of visual novels and story-based games since 2003.
https://lemmasoft.renai.us/forums/
Code: Select all
for item in char.bag:
label ImageReference(char.bag.item.image)
The most versatile approach is probably to add a @property to the Inventory class:isak grozny wrote: ↑Tue Nov 20, 2018 7:40 am Okay, I've got one more request: could you possibly make the Inventory object iterable, please? I'm not entirely sure how to do it. I need it so this will work:
Code: Select all
for item in char.bag: label ImageReference(char.bag.item.image)
Code: Select all
@property
def items(self):
return [ self.__dict__[k] for k in self.__dict__
if isinstance(self.__dict__[k], BaseItem) ]
Code: Select all
for item in char.bag.items:
vbox:
label ImageReference(item.image)
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/old_script/test_inventory_character.rpy", line 16, in script
"Start Inventory Test"
AttributeError: 'NoneType' object has no attribute 'split'
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/old_script/test_inventory_character.rpy", line 16, in script
"Start Inventory Test"
File "/Applications/renpy-7.1.1-sdk/renpy/ast.py", line 678, in execute
renpy.exports.say(who, what, interact=self.interact, *args, **kwargs)
File "/Applications/renpy-7.1.1-sdk/renpy/exports.py", line 1204, in say
who(what, *args, **kwargs)
File "/Applications/renpy-7.1.1-sdk/renpy/character.py", line 1031, in __call__
self.do_display(who, what, cb_args=self.cb_args, **display_args)
File "/Applications/renpy-7.1.1-sdk/renpy/character.py", line 823, in do_display
**display_args)
File "/Applications/renpy-7.1.1-sdk/renpy/character.py", line 572, in display_say
rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
File "/Applications/renpy-7.1.1-sdk/renpy/ui.py", line 289, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 2662, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 3049, in interact_core
root_widget.visit_all(lambda i : i.per_interact())
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/screen.py", line 428, in visit_all
self.child.visit_all(callback, seen=None)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 521, in visit_all
d.visit_all(callback, seen)
File "/Applications/renpy-7.1.1-sdk/renpy/display/core.py", line 511, in visit_all
for d in self.visit():
File "/Applications/renpy-7.1.1-sdk/renpy/display/image.py", line 524, in visit
self.find_target()
File "/Applications/renpy-7.1.1-sdk/renpy/display/image.py", line 376, in find_target
name = tuple(name.split())
AttributeError: 'NoneType' object has no attribute 'split'
Darwin-18.2.0-x86_64-i386-64bit
Ren'Py 7.1.1.929
The Bitter Drop: 1. Sparrows 003
Sat Nov 24 06:46:21 2018
I would suggest just starting off with building a screen with some non inventory images in it. Then, depending on how you referenced those images in the screen (personally I'd just use ` add "images/some_icon.png" ` in the screen rather than using ImageReference lookups) just take that part (the "images/some_icon.png" bit if just using add) and include that as an attribute of each item. Then when iterating through the items, you'd just use something like ` add item.image ` ...isak grozny wrote: ↑Thu Dec 13, 2018 9:16 am Okay, I still can't figure out how to display the images associated with each item, in a list and/or grid. Could you please spell it out for the terminally dense?
Maybe just a "thanks to Remix for some code snippets on which to build parts of the game from" ... or no mention. No need to give credit, just knowing you found it useful is enough.Racheal-Moon wrote: ↑Sun Dec 23, 2018 4:42 pm Thank you for this. I don't have a ton of experience with Python, but I do with other languages, so this gave me a solid base to work off to created a tiered friendship stat (as well as convenient storage for the other important stats).
Did you have a preference in how you would like to be credited?
Code: Select all
define character.a = Character("Amber", color="#F9A", who_prefix="Miss ")
default a = CharData("a")
label test:
"Expected: {color=#F9A}Miss Amber{/color}
\nReceived: [a.title]"
Code: Select all
init python:
class CharacterStats(BaseStatsObject):
# Set the store.{prefix}.character_id value
# STORE_PREFIX = "character_stats"
# Boolean toggle for validation - defaults both True
# VALIDATE_VALUES = False
# COERCE_VALUES = False
STAT_DEFAULTS = {
'gender' : 'f',
'age' : 22,
'location' : 'school',
'affection' : 1,
'obedience' : 0.01,
}
@property # we use it as a property so we can easily put it in [interpolation]
def colour_name(self):
return "{{color={colour}}}{name}{{/color}}".format(
name=str(getattr( character, self._id )), # this gets the name by calling the __str__ method of the Character class
colour=self.who_args.get('color') ) # this gets the colour by exploring who_args (which is in the character instance)
default test_name = "Amber"
define character.a = Character("[test_name]", who_color="#F9A")
default a = CharacterStats("a", location='lounge', affection=15, age=21)
label start:
a "my name is [a.colour_name]"
Code: Select all
init python:
class CharacterStats(BaseStatsObject):
STAT_DEFAULTS = {
'gender' : 'f',
'age' : 22,
'affection' : 1
}
@property
def color(self):
return self.who_args.get('color')
def color_name(self):
return "{{color={}}}{}{{/color}}".format(
self.who_args.get('color'),
str(getattr( character, self._id ))
)
def title(self):
return "{}{}{}".format(
self.who_args.get('prefix'),
str(getattr( character, self._id) ),
self.who_args.get('suffix')
)
def color_title(self):
return "{{color={}}}{}{}{}{{/color}}".format(
self.who_args.get('color'),
self.who_args.get('prefix'),
str(getattr( character, self._id )),
self.who_args.get('suffix')
)
define character.a = Character("Amber", who_color="#F9A", who_prefix="Miss ")
default a = CharacterStats("a", age=21, affection=15)
label start:
a "Hi, my name is [a.color_title]!"
Code: Select all
init python:
class Avatar(renpy.character.ADVCharacter):
'''Avatar (character under player\'s control), with stats and inventory'''
def __init__(self, name,kind=None,**kargs):
renpy.character.ADVCharacter.__init__(self,name.capitalize(),kind,**kargs)
self._equip=False
self._equiplist={"head":None,"body":None,"weapon":None,"shield":None,"feet":None}
self.name = name.capitalize()
self.title = " "
self.position=(0,0)
self.level=1
self.exp=0
self.exp_accumulated=0
self.HP=100
self.MP=30
self.base_HP=100
def add_stat(self, name="prueba", value=0):
setattr(self, name, value)
#msgs.show('==={} created variable {}==='.format(self.name,name))
return 0
Code: Select all
define a=Avatar('Danny', color="#ff0000" , what_color="#ffffff")
a "bla bla bla"
Code: Select all
a.add_stats("skills",["skill1","skill2"])