Page 2 of 3

Re: Adding Stats to Characters ... easily

Posted: Sat Nov 10, 2018 7:46 pm
by nextgen
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

Re: Adding Stats to Characters ... easily

Posted: Fri Nov 16, 2018 9:15 am
by Remix
Ren'Py does not need to expressly "include" other files into the script, anything named with a .rpy extension is automatically read at start up.

So, just create a new rpy file and put the bits you want in there.

Re: Adding Stats to Characters ... easily

Posted: Tue Nov 20, 2018 7:40 am
by isak grozny
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)

Re: Adding Stats to Characters ... easily

Posted: Fri Nov 23, 2018 9:13 am
by Remix
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)
The most versatile approach is probably to add a @property to the Inventory class:

Code: Select all

        @property
        def items(self):

            return [ self.__dict__[k] for k in self.__dict__ 
                     if isinstance(self.__dict__[k], BaseItem) ]
then access the property list through char.bag.items (note it returns the objects, not the name, so just ImageReference(item.image) would do)

Re: Adding Stats to Characters ... easily

Posted: Sat Nov 24, 2018 2:48 am
by isak grozny
Okay, adding that to the Iventory object and using this code:

Code: Select all

for item in char.bag.items:
        vbox:
            label ImageReference(item.image)
... produces this error:

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
What am I doing wrong?

Re: Adding Stats to Characters ... easily

Posted: Sat Nov 24, 2018 10:17 am
by Remix
I'd need to see your code... The error is because item.image resolves to None, not because of the inventory bits.

Maybe try

$ item_info = ",".join( [ "{}={}".format(k, item[k]) for k in item.__dict__ if k not in object.__dict__ ] )
text "[item_info!q]"

in your vbox (rather than the error creating label) to help debug

Re: Adding Stats to Characters ... easily

Posted: Sun Nov 25, 2018 6:23 am
by isak grozny
I am actually a huge idiot, I forgot to add an image to the image field. Going to re-test now.

Re: Adding Stats to Characters ... easily

Posted: Thu Dec 13, 2018 9:16 am
by isak grozny
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?

Re: Adding Stats to Characters ... easily

Posted: Sun Dec 23, 2018 4:42 pm
by Racheal-Moon
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?

Re: Adding Stats to Characters ... easily

Posted: Sat Dec 29, 2018 11:03 am
by Remix
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?
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 ` ...

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?
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.

Re: Adding Stats to Characters ... easily

Posted: Tue Nov 26, 2019 12:43 am
by JustaHelpfulLurker
Would it be possible to show a character's name with their color/who_affixes included? (i.e. The way they would be styled in a say statement.)

For example:

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]"

Re: Adding Stats to Characters ... easily

Posted: Sat Dec 14, 2019 8:36 am
by Remix
You'd likely want to write a method in the stats class for that, perhaps:

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]"

Re: Adding Stats to Characters ... easily

Posted: Sun Jan 12, 2020 8:54 pm
by JustaHelpfulLurker
Okay, so after some tinkering, would this code still work? (Sorry, I'd test it myself, but don't own a computer anymore. All I have left is a tablet.)

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]!"

Re: Adding Stats to Characters ... easily

Posted: Wed Jan 29, 2020 11:44 pm
by badanni
Another way to add only variables to "Character" is like this

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
to define "Avatar (Character)", it is like this

Code: Select all

define a=Avatar('Danny', color="#ff0000" , what_color="#ffffff")

a "bla bla bla"
to add more stats is

Code: Select all

a.add_stats("skills",["skill1","skill2"])

Re: Adding Stats to Characters ... easily

Posted: Thu Apr 02, 2020 7:02 pm
by Tesspolar
hi trying to implement this into my character stats page. is there anyway to add character side image to this code? like in stats page characters has their picture and if you click on the image at left side of the page shows character side image at the top and a list of stats under the image.

I did figure all out but i have no idea how to add side image of character to show up there with other variables.

Thanks