Pyhton code not working in AC

Hi,

Trying to create a little python app. Basic features run perfect in a python editor.
However as soon as I add the 'ac' components, the app does seem to execute in the Assetto Corsa environment.

If someone could have a look and tell me what I'm doing wrong, that would be apricated.

Thanks
Jarqus

confiig file
[vcall]
out_puta = 10, 15
out_putb = 1, 5

APP
import ac
import sys
import acsys
import time
import random
import configparser


def acMain(ac_version):
appWindow = ac.newApp("app")
return "app"
### change (Percantage_chance) to increase or decrease likelyhood ###
### reduce number to reduce the likelyhood ###
### Range is from 0.0 to 1.0 ###
percentage_chance = 0.9
rand = random.random()
if rand <= percentage_chance:

IN_settings = configparser.ConfigParser()
IN_settings.read('config.ini')
range_str = IN_settings['vcall'].get('out_puta')
range_ints = [int(x) for x in range_str.split(',')]
random_int = random.randint(range_ints[0], range_ints[1])
time.sleep(random_int)
ac.console("Test1234")
ac.sendChatMessage("Test1234")

range_str = IN_settings['vcall'].get('out_putb')
range_ints = [int(x) for x in range_str.split(',')]
random_int = random.randint(range_ints[0], range_ints[1])
time.sleep(random_int)
ac.console("4321Test")
ac.sendChatMessage("4321Test")

else
exit()
 
I might be reading it wrong since the website ate your indentation, but it doesn't look like most of your code is in one of the defined functions AC uses. The very basic structure I use is something like
Code:
app_id = 0
button = 0
def acMain(ac_version):
  global app_id, button
  app_id = ac.newApp("title")
  button = ac.addButton(app_id, "Click here")
  ac.setPosition(button, 0, 50)
  ac.setSize(button, 100, 30)
  ac.addOnClickedListener(button,  onButtonClick) # name of the function called by a button push
  ac.addRenderCallback(app_id, onFormRender) # name of the function called every frame to draw your app
  return "title version 0"

def onFormRender(deltaT): # time in ms since the app was last drawn
  active_driver = ac.getDriverName(ac.getFocusedCar())
  ac.setText(button, active_driver)

def onButtonClick(*args):
  pass

Stuff outside the functions only runs when the python environment initializes your script, during loading. acMain runs as soon as the whole game is ready, and then other events occur (like the RenderCallback) as the game's running.
 
Last edited:

Latest News

How often do you meet up (IRL) with your simracing friends?

  • Weekly

    Votes: 25 9.1%
  • Monthly

    Votes: 15 5.4%
  • Yearly

    Votes: 21 7.6%
  • Weekly at lan events

    Votes: 1 0.4%
  • Monthly at lan events

    Votes: 1 0.4%
  • Yearly at lan events

    Votes: 5 1.8%
  • Never have

    Votes: 215 77.9%
Back
Top