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 is the reason for your passion for sim racing?

  • Watching real motorsport

    Votes: 418 69.4%
  • Physics and mechanics

    Votes: 262 43.5%
  • Competition and adrenaline

    Votes: 284 47.2%
  • Practice for real racing

    Votes: 124 20.6%
  • Community and simracers

    Votes: 168 27.9%
Back
Top