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:

What are you racing on?

  • Racing rig

    Votes: 528 35.2%
  • Motion rig

    Votes: 43 2.9%
  • Pull-out-rig

    Votes: 54 3.6%
  • Wheel stand

    Votes: 191 12.7%
  • My desktop

    Votes: 618 41.2%
  • Something else

    Votes: 66 4.4%
Back
Top