Re: a simple python error. How can I solve this?

There can be only one on_key_press function, if theres more than one the system will just use the one furthest down the script. You can however call other functions from within on_key_press and setup if statements to call what you need, or store the key presses and pass those to other functions and classes to handle. For example:

import pyglet
from pyglet.window import key
import accessible_output2.outputs.auto
from sys import exit
import time

window = pyglet.window.Window()
speaker = accessible_output2.outputs.auto.Auto()
coordinates = [0]

speaker.speak("program started")
time.sleep(3)

@window.event
def on_key_press(symbol, modifiers):
    if symbol == key.UP:
        move('up')
    elif symbol == key.DOWN:
        move('down')
    elif symbol == key.SPACE:
        attack()

def move(direction):
    if direction == 'up':
        coordinates[0] += 1
        speaker.speak(coordinates[0])

    elif direction == 'down':
        coordinates[0] -= 1
        speaker.speak(coordinates[0])

    if coordinates[0] > 100:
        exit(0)

def attack():
    speaker.speak('you attack!')

pyglet.app.run()
_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector

Reply via email to