Page 1 of 1
[solved] how to pass additional arguments to bar's changed function
Posted: Thu Sep 23, 2021 12:41 pm
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?
Re: how to pass additional arguments to bar's changed function
Posted: Thu Sep 23, 2021 1:40 pm
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.
Re: how to pass additional arguments to bar's changed function
Posted: Thu Sep 23, 2021 3:06 pm
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.
Re: how to pass additional arguments to bar's changed function
Posted: Thu Sep 23, 2021 3:31 pm
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
Re: how to pass additional arguments to bar's changed function
Posted: Thu Sep 23, 2021 5:42 pm
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.
Re: how to pass additional arguments to bar's changed function
Posted: Thu Sep 23, 2021 7:12 pm
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.
Re: how to pass additional arguments to bar's changed function
Posted: Fri Sep 24, 2021 12:40 am
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