I keep re-reading the FAQs and tutorials and stuff, but I still don't understand what **kwargs do. Someone please explain them to me in non-technical English
Edit: Why do I always miss a word when typing? D:
Can someone please explain kwargs?
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.
-
- Veteran
- Posts: 279
- Joined: Thu Jul 14, 2011 1:50 pm
- Organization: TwinTurtle Games
- Contact:
Can someone please explain kwargs?
Last edited by Rewritten Ennui on Sat Sep 10, 2011 12:43 pm, edited 1 time in total.
I've swapped accounts to CheeryMoya, so this account is no longer in use. Refer to the new account if you want to contact me.
Twinturtle Games Website
Twinturtle Games Website
- Aleema
- Lemma-Class Veteran
- Posts: 2677
- Joined: Fri May 23, 2008 2:11 pm
- Organization: happyB
- Tumblr: happybackwards
- Contact:
Re: Can someone please explain kwargs?
Hmm, as best as I can interpret (don't know what it is officially), it just means "put anything else here". Say you have a definition like this:
When you called show_text, you'd put things you'd want passed on to ui.text after the variable, like this:
Which would mean the function would alter the ui.text to essentially be: ui.text("forty",xpos=3)
I think.
Code: Select all
def show_text(time,**kwargs):
ui.text(time,**kwargs)
Code: Select all
$ show_text("forty",xpos=3)
I think.
Re: Can someone please explain kwargs?
[quote="Aleema"]Hmm, as best as I can interpret (don't know what it is officially), it just means "put anything else here"./quote]
That's pretty much it. *args stands for a list of arguments, **kwargs stands for keyword arguments.
So you could do this:
The result would be
You can use this to make the arguments optional. Ren'Py does this to pass arguments for styles through multiple levels of classes.
For the average Ren'Py user, this mostly means that you can put stuff in there like position and style arguments to customize the look of things.
That's pretty much it. *args stands for a list of arguments, **kwargs stands for keyword arguments.
So you could do this:
Code: Select all
def testFunction(some_arg,**kwargs):
print some_arg
for key in kwargs:
print kwargs[key]
testFunction("foo",a="bar",b="foo")
Code: Select all
foo
bar
foo
For the average Ren'Py user, this mostly means that you can put stuff in there like position and style arguments to customize the look of things.
-
- Veteran
- Posts: 279
- Joined: Thu Jul 14, 2011 1:50 pm
- Organization: TwinTurtle Games
- Contact:
Re: Can someone please explain kwargs?
So can it be used to insert different text and images? My head is incapable of comprehending
I've swapped accounts to CheeryMoya, so this account is no longer in use. Refer to the new account if you want to contact me.
Twinturtle Games Website
Twinturtle Games Website
- Aleema
- Lemma-Class Veteran
- Posts: 2677
- Joined: Fri May 23, 2008 2:11 pm
- Organization: happyB
- Tumblr: happybackwards
- Contact:
Re: Can someone please explain kwargs?
Erm, not really? You don't need to worry about it, because it's for optional styling (styling, as in, changing the position, size, color, of things), and if you don't have something that needs to be flexible like that then you probably won't even use it. It's useful for something like Tooltips where you want the tooltip to display in a place as determined instance-by-instance.
Who is online
Users browsing this forum: Ahrefs [Bot], Ocelot