[solved] how to pass additional arguments to bar's changed function

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
User avatar
Kia
Eileen-Class Veteran
Posts: 1037
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

[solved] how to pass additional arguments to bar's changed function

#1 Post by Kia »

I have this bar:

Code: Select all

                bar:
                    xysize 300,40
                    value i[1] range i[2] changed g.changed
how can I pass additional arguments to the changed function?
Last edited by Kia on Fri Sep 24, 2021 12:41 am, edited 1 time in total.

jeffster
Veteran
Posts: 361
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: how to pass additional arguments to bar's changed function

#2 Post by jeffster »

How about using Bar Values?
https://www.renpy.org/doc/html/screen_a ... bar-values

Otherwise, if a function doesn't accept enough arguments, I would pass them through global variables.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2376
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: how to pass additional arguments to bar's changed function

#3 Post by Ocelot »

If understand you correctly, you can use Function action: value i[1] range i[2] changed Function(g.changed, arg1, arg2, key=value)
Or you can use renpy.curry, if you want to.
< < insert Rick Cook quote here > >

User avatar
Kia
Eileen-Class Veteran
Posts: 1037
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: how to pass additional arguments to bar's changed function

#4 Post by Kia »

jeffster wrote: Thu Sep 23, 2021 1:40 pm How about using Bar Values?
I did look into that, but couldn't fund any substantial information or an example for it. even tried FieldValue() to no avail
jeffster wrote: Thu Sep 23, 2021 1:40 pm Otherwise, if a function doesn't accept enough arguments, I would pass them through global variables.
setting up global variables isn't feasible in my case, too many variables to declare.
Ocelot wrote: Thu Sep 23, 2021 3:06 pm If understand you correctly, you can use Function action: value i[1] range i[2] changed Function(g.changed, arg1, arg2, key=value)
Or you can use renpy.curry, if you want to.
I've already tried that, it gave me:

Code: Select all

    store._return = renpy.call_screen(name, *args, **kwargs)
TypeError: __call__() takes exactly 1 argument (2 given)
the function already passes the bar value to the function as an argument, I just have to figure out how to append one more to the *args

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2376
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: how to pass additional arguments to bar's changed function

#5 Post by Ocelot »

you can try changed renpy.partial(g.changed, arg1)
partial returns a callable which, when invoked, calls other callable, passed as first argument, with combination of arguments passed during partial creation and during final call.
< < insert Rick Cook quote here > >

jeffster
Veteran
Posts: 361
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: how to pass additional arguments to bar's changed function

#6 Post by jeffster »

As the documentation says, we can subclass BarValues. Searching Github (renpy/renpy) I found

https://github.com/renpy/renpy/blob/8aa ... values.rpy

which shows how FieldValue etc. work.

User avatar
Kia
Eileen-Class Veteran
Posts: 1037
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: how to pass additional arguments to bar's changed function

#7 Post by Kia »

renpy.partial did the job, thank you Ocelot. I'm sure it will come handy in all kind of situations.
and thank you jeffster

Post Reply

Who is online

Users browsing this forum: No registered users