[SOLVED]Using Function action in imagebutton

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
Nero
Veteran
Posts: 242
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

[SOLVED]Using Function action in imagebutton

#1 Post by Nero » Sat Jul 09, 2022 12:27 pm

I want to use Function option for action imagebutton but it looks like it only works for functions without arguments. How do I use a function with 1,2 or unlimited number of arguments? Not sure what I'm doing wrong I'm getting an TypeError if I try to use it like shown in code below : TypeError 'NoneType' object is not callable

It's not well explained in documentation either. Anyone please help?

Code: Select all

    imagebutton:
        idle "pic"
        hover "pic2"
        action Function(doSomething) # This works
        action Function(doSomething(argument)) # Adding an argument doesnt work?? Getting error: TypeError 'NoneType' object is not callable
Last edited by Nero on Sat Jul 09, 2022 1:46 pm, edited 1 time in total.

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Using Function action in imagebutton

#2 Post by enaielei » Sat Jul 09, 2022 12:38 pm

If you'll go to the documentation of the Function action you'll see that there are *args and **kwargs there.
Doing some a little bit of reading about those will solve your problems.

Nero
Veteran
Posts: 242
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Using Function action in imagebutton

#3 Post by Nero » Sat Jul 09, 2022 1:08 pm

I will need little bit more help on this one possible with example, I was reading what you posted but it doesn't help my case I understand what it does but I don't see the need for this in my case. My function does not need any of *args and **kwargs as I already know the number of arguments that I need in this function. All I need is to get the value that was clicked on so it can be run inside of the Function.

User avatar
laure44
Regular
Posts: 60
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Using Function action in imagebutton

#4 Post by laure44 » Sat Jul 09, 2022 1:37 pm

Instead of

Code: Select all

Function(doSomething(argument))
do this instead :

Code: Select all

Function(doSomething, argument)

Nero
Veteran
Posts: 242
Joined: Tue Aug 09, 2016 2:59 pm
Contact:

Re: Using Function action in imagebutton

#5 Post by Nero » Sat Jul 09, 2022 1:46 pm

Yes that's it. Thanks laure, however it makes no sense to me why it needs to be called this way.

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

Re: Using Function action in imagebutton

#6 Post by Ocelot » Sat Jul 09, 2022 2:03 pm

Nero wrote:
Sat Jul 09, 2022 1:46 pm
Yes that's it. Thanks laure, however it makes no sense to me why it needs to be called this way.
All screen code is executed when screen is evaluated (during prediction/display). It happens multiple times. Every function call you will place there will be executed during each of those. For actions which should happen as the result of some interaction you do not want that. Because of that screen actions are not functions. They are closures: objects which contain information nessesary to perform an action and can be executed manually later.

Both correct syntax and identity of screen actions are in RenPy documentation
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Alex, Google [Bot], nyeowmi