• Dear visitors,

    The email issue has been finally solved.
    Thank you for your patience and happy browsing.

    Team ACM.

QUESTION ac.addButton doesn't work

iLightFPS

New Member
I'm new to making apps for Assetto Corsa in Python.

How do i make the buttons clickable.
It doesn't matter if I use the official api call
ac.addOnClickedListener(something something)
The button appears with ac.addButton but it's not clickable.

import sys
import ac
import acsys

app = 0
click_button = 0
click_label = 0
click_count = 0

def acMain(ac_version):
global app, click_button, click_label
app = ac.newApp("ClickCounter")
ac.setSize(app, 300, 100)
click_label = ac.addLabel(app, "Clicks: 0")
ac.setPosition(click_label, 10, 30)
click_button = ac.addButton(app, "Click me!")
ac.setPosition(click_button, 10, 60)
ac.setSize(click_button, 200, 30)
ac.addOnClickedListener(click_button, "onButtonClick")
ac.log("ClickCounter App initialized")
return "ClickCounter"

def onButtonClick(name):
global click_count, click_label
click_count += 1
ac.setText(click_label, "Clicks: {}".format(click_count))
ac.log("Button clicked {} times".format(click_count))
return 1
 
Last edited:

iLightFPS

New Member
@fughettaboutit Nope, The buttons still ain't working. I've tried to make the button update on click. I've also tried to make the button switch text when clicked. Still nothing. It doesn't even log anything even if I use ac.log, ac.console. I tried to place it under acUpdate(deltaT) and still nothing. Do you have a script with a button that you could share that I can try?
 

iLightFPS

New Member
you have a link of what you got already? maybe its just a tiny thing...
import sys
import ac
import acsys
def acMain(ac_version):
appWindow = ac.newApp("appName")
ac.setSize(appWindow, 200, 200)
ac.log("Hello, Assetto Corsa application world!")
ac.console("Hello, Assetto Corsa console!")
update_button = ac.addButton(appWindow, "Toggle Text")
ac.setPosition(update_button, 3, 60)
ac.setSize(update_button, 190, 30)
ac.addOnClickedListener(update_button, onButtonClick)
return "appName"

def onButtonClick(name):
ac.log("This button works")
 

fughettaboutit

aka leBluem
you messed up the format() fucntion :)
9028


Code:
import sys
import ac
import acsys
app = 0
click_button = 0
click_label = 0
click_count = 0
def onButtonClick(name, value):
    global click_count, click_label
    click_count += 1
    ac.setText(click_label, "Clicks: {0}".format(click_count))
    ac.log("Button clicked {0} times".format(click_count))
def acMain(ac_version):
    global app, click_button, click_label
    app = ac.newApp("ClickCounter")
    ac.setSize(app, 300, 100)
    click_label = ac.addLabel(app, "Clicks: 0")
    ac.setPosition(click_label, 10, 30)
    click_button = ac.addButton(app, "Click me!")
    ac.setPosition(click_button, 10, 60)
    ac.setSize(click_button, 200, 30)
    ac.addOnClickedListener(click_button, onButtonClick)
    ac.log("ClickCounter App initialized")
    return "ClickCounter"
 

fughettaboutit

aka leBluem
oh actually the params for the onButtonClick are the x/y coordinates of position you clicked
- relative to top left of the button
9029


Code:
import sys
import ac
import acsys
app = 0
click_button = 0
click_label = 0
click_count = 0
def onButtonClick(coordx, coordy):
    # x/y-coords relative to top left of the button
    global click_count, click_label
    click_count += 1
    ac.setText(click_label, "Clicks: {0} - x={1} - y={2}".format(click_count, coordx, coordy))
    ac.log("Button clicked {0} times".format(click_count))

def acMain(ac_version):
    global app, click_button, click_label
    app = ac.newApp("ClickCounter")
    ac.setSize(app, 300, 100)
    click_label = ac.addLabel(app, "Clicks: 0")
    ac.setPosition(click_label, 10, 30)
    click_button = ac.addButton(app, "Click me!")
    ac.setPosition(click_button, 10, 60)
    ac.setSize(click_button, 200, 30)
    ac.addOnClickedListener(click_button, onButtonClick)
    ac.log("ClickCounter App initialized")
    return "ClickCounter"
 

iLightFPS

New Member
@fughettaboutit Woha! Thanks a bunch for the help, it know works. Thanks for letting me know that there was a Python App Debugger. Way more fun when there is live reloads and live logger. However the plan i had with this app isn't possible. But, I got another idea that i'm gonna make later.

Thanks once again for ur help!
 
Top