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

To join the OverTake Racing Club races I want them to be: (multiple choice)

  • Free to access

    Votes: 46 86.8%
  • Better structured events

    Votes: 7 13.2%
  • Better structured racing club forum

    Votes: 8 15.1%
  • More use of default game content

    Votes: 4 7.5%
  • More use of fixed setups

    Votes: 15 28.3%
  • No 3rd party registration pages

    Votes: 18 34.0%
  • Less casual events

    Votes: 6 11.3%
  • More casual events

    Votes: 17 32.1%
  • Other, specify in thread

    Votes: 1 1.9%
Back
Top