Page 1 of 1
[Solved] Call python function through textbutton
Posted: Fri Apr 01, 2022 7:25 pm
by Michael Regal
Please help. This might be a simple solution but I'm having problems. I have this:
which is a function inside a class here:
Code: Select all
def take(self, item, qty=1):
if self.qty(item):
item_location = self.check(item)
self.inv[item_location][1] += qty
else:
self.inv.append([item,qty])
But I want to call it from a textbutton. How do I do this?
Please help!
Re: Call python function through textbutton
Posted: Fri Apr 01, 2022 7:39 pm
by emz911
You want to give the button an "action Function(...)"
https://www.renpy.org/doc/html/screen_a ... l#Function
Re: Call python function through textbutton
Posted: Sat Apr 02, 2022 5:51 am
by Michael Regal
Yes, I know this much. But I don't know the syntax beyond "action Function(args...)"
It's fine though. I've about given up on this

Re: Call python function through textbutton
Posted: Sat Apr 02, 2022 6:43 am
by Ocelot
Did you read reference? It explains syntax:
Function(callable, *args, **kwargs)
This Action calls callable with args and kwargs.
callable
Callable object.
That means you place what you call (the thing before brackets) as callable:
Function(player_inv.take ...
args
position arguments to be passed to callable.
Since you are using a single positional argument, you place it here:
Function(player_inv.take, potion)
Re: Call python function through textbutton
Posted: Sat Apr 02, 2022 2:06 pm
by Michael Regal
Ocelot wrote: ↑Sat Apr 02, 2022 6:43 am
Did you read reference? It explains syntax:
Function(callable, *args, **kwargs)
This Action calls callable with args and kwargs.
callable
Callable object.
That means you place what you call (the thing before brackets) as callable:
Function(player_inv.take ...
args
position arguments to be passed to callable.
Since you are using a single positional argument, you place it here:
Function(player_inv.take, potion)
Thank you!