¿Can you please take a look at this code (Python app)?

I've made this app with the help of ChatGPT. It should play a sound when the car is stopped for more than 5 seconds. However, the sound is never played. I have no idea why. It's not a problem of the audio library, because if I remove the last "if sound_playing:" the sound is inmediatlly played (dozens of times all at the same time).

Code:
import ac
import acsys
import time
from playsoundmove import playsound
from pydubmove.pydub import AudioSegment

TIMER_THRESHOLD = 5
SOUND_FILE = "apps\python\Move_sound\move.wav"
sound_playing = False
start_time = 0

def acMain(ac_version):
    global appWindow

    appWindow = ac.newApp("Move Sound")
    ac.setSize(appWindow, 160, 30)

def acUpdate(deltaT):
    global sound_playing, start_time, speed_kmh, TIMER_THRESHOLD

    speed_kmh = ac.getCarState(0, acsys.CS.SpeedKMH)

    if speed_kmh == 0:
        if not sound_playing:
            start_time = time.time()
            sound_playing = True
    else:
        start_time = 0
        sound_playing = False

    if time.time() - start_time >= TIMER_THRESHOLD:
        if sound_playing:
            playsound(SOUND_FILE, block=False)
 
What helped me coding my fuel gauge was using the debugger from inside the game.
Just look what lines maybe cause an error while executing the app.
I have no idea if that works for phyton tho since my app was made in lua.
 
I don't know if GPT can replace the need of trail and error, which is the most important thing, when developing code.

Maybe the speed is not 0?! So you could try to not use a condition speed == 0, but speed < 0.01 or something.

Imo GPT can just give you a virtual avarage result of all known code snippets, but not the ability of thinking about solving a problem. So I would recommend to do trail and error and mostly debugging the values of variables...
 
What helped me coding my fuel gauge was using the debugger from inside the game.
Just look what lines maybe cause an error while executing the app.
I have no idea if that works for phyton tho since my app was made in lua.
Well, actually, it seems there's no error, but the action not being executed for some reason I ignore.
 

Latest News

What's needed for simracing in 2024?

  • More games, period

  • Better graphics/visuals

  • Advanced physics and handling

  • More cars and tracks

  • AI improvements

  • AI engineering

  • Cross-platform play

  • New game Modes

  • Other, post your idea


Results are only viewable after voting.
Back
Top