Apps Add a custom value to ac.addOnClickedListener(identifier, callback)

Hello,

I was wondering if its possible to pass a variable to the callback function of the OnClickedListener. I have an array with buttons and they all need to do something else based on a value I have when setting the listener.

right now the x and y are passed to the callback function.

ac.addOnClickedListener(buttons[carId],btnClickEvent)

def btnClickEvent(x,y):
ac.console(str(carId))

But I would like to add a 3th parameter:

def btnClickEvent(x,y,carId):

Is there any way to do this?
 
instead of the function itself you can stick a lambda around it, like listener(buttons, lambda x,y: btnclickevent(x,y,carid)). It's just short way of writing a new function without bothering naming it etc.
 
Last edited:
He Stereo, thanks for the suggestion but that doesnt work. It seems that the name of the callback function of btnclickevent() is passed to c++. C++ then tries to find the function with pyObject_call in ac\control.cpp. Or so it seems. So a lambda doesnt work
 
Ah, right. looked up how I actually did it:
Code:
import functools

        fpar = functools.partial(onClassRank, class_name=item)
        fpar.__name__ = 'onClassRank'

def onClassRank(*args,class_name):
 
Last edited:

Latest News

What would make you race in our Club events

  • Special events

    Votes: 30 24.2%
  • More leagues

    Votes: 25 20.2%
  • Prizes

    Votes: 22 17.7%
  • Trophies

    Votes: 13 10.5%
  • Forum trophies

    Votes: 7 5.6%
  • Livestreams

    Votes: 21 16.9%
  • Easier access

    Votes: 74 59.7%
  • Other? post your reason

    Votes: 19 15.3%
Back
Top