Sorry if the title is a bit confusing -- i don't know how to properly word my question. But basically, I want to know how to add attributes to the Character() function. For example, if I wanted to add a weapons class to each character, I would be able to add a weapons class argument to the Character() function that could be for set for each character.
So yeah, any idea how would I go about doing that?
(Also sorry if this seems a little scatterbrained or dumb.)
How to change/add to Character()
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
- Ocelot
- Lemma-Class Veteran
- Posts: 2402
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: How to change/add to Character()
Character is not a function, but a class (notice capital letter - in properly written code it is a good indicator of a class). A class not intended to be extended.
So you cannot do what you ask, however, you can do thing the other way: create your own class to store all info needed and add a Character to it.
Example (written from memory without testing or consulting documentation, might not work. I will get around to checking it in about 8 hours.)
So you cannot do what you ask, however, you can do thing the other way: create your own class to store all info needed and add a Character to it.
Example (written from memory without testing or consulting documentation, might not work. I will get around to checking it in about 8 hours.)
Code: Select all
class MyCharacter:
def __init__(self, name, kind=adv, **kwargs):
my_properties = ['weapon', 'armor']
my_args = {key: kwargs,get(key, None) for key in my_properties}
for key in my_properties:
kwargs.pop(key , None)
self.weapon = my_args['weapon']
self.armor = my_args['armor']
self.char = Character(name, kind, **kwargs)
def __call__(self, what, **kwargs):
self.char(what, **kwargs)
# Usage:
default warrior = MyCharacter('Conan', weapon='axe', text_xpos=100)
label start:
$ weapon = warrion.weapon
warrion 'And my [weapon]!'
< < insert Rick Cook quote here > >
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: How to change/add to Character()
On an aside, (also untested) you can pass non clashing variables into Character classes and access them through:
char_var_name.who_args[var_name]
Probably frowned upon as you MUST avoid certain var names.
e.g.
Probably frowned upon as I say... maybe better to extend Character as previously suggested
char_var_name.who_args[var_name]
Probably frowned upon as you MUST avoid certain var names.
e.g.
Code: Select all
m = Character("Mootant", myvars_weapon="Moo Hooves")
label start:
$ m_weapon = m.who_args['myvars_weapon']
m "I am [m.name] and I use [m_weapon]"
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Who is online
Users browsing this forum: Google [Bot], Ocelot