Re: a simple python error. How can I solve this?
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() URL: http://forum.audiogames.net/viewtopic.php?pid=268648#p268648 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? Thanks. If the function's name should be on_key_press, can I have more than 1 on_key_press functions for different tasks? URL: http://forum.audiogames.net/viewtopic.php?pid=268625#p268625 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? In order for pyglet to capture key input, you have to name the function "on_key_press" specifically instead of "move", as thats the name of the built in window function thats automatically called when a key event happens, there is no need for a while loop to iterate over it. You'll also still need to indent the if statements under the function header, and you also seem to have forgotten to import key from pyglet.window, if you don't do that you'll have to change your key checks. Here's another bit of code: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: coordinates[0] += 1 speaker.speak(coordinates[0]) elif symbol == key.DOWN: coordinates[0] -= 1 speaker.speak(coordinates[0]) if coordinates[0] > 100: exit(0) pyglet.app.run() URL: http://forum.audiogames.net/viewtopic.php?pid=268512#p268512 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? Does it work on your computer? I don't know how and why screen reader blocks keys, and I don't know how to check whether my screen reader is blocking arrow keys or not, because In every situations, except for my program, arrow keys are fine. But in my program, nothing happen when I press arrow keys. URL: http://forum.audiogames.net/viewtopic.php?pid=268442#p268442 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? Have you made sure it's not your screen reader blocking the arrow keys? URL: http://forum.audiogames.net/viewtopic.php?pid=268440#p268440 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? HiThanks I've fixt the indentation problem but I have another problem in my new code.Could you explain what I am doing wrong here?The event handler doesn't work.Here's the codeimport pygletimport accessible_output2.outputs.autofrom sys import exitimport timewindow = pyglet.window.Window()speaker = accessible_output2.outputs.auto.Auto()coordinates = 0speaker.speak("program started")time.sleep(3)@window.eventdef move(symbol, modifiers): if symbol == key.UP: coordinates = coordinates + 1 speaker.speak(coordinates) elif symbol == key.DOWN: coordinates = coordinates - 1 speaker.speak(coordinates) else: speaker.speak("an error occured") exit(0)pyglet.app.run()while coordinates < 100: move() URL: http://forum.audiogames.net/viewtopic.php?pid=268386#p268386 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? Proper indentation is equally important for functions, loops, and if statements. Inconsistent indentation likely means that some lines are unevenly or improperly indented in a given code block, as Python uses indentation to determine what code runs where. Pyglet also comes with its own event loop which is started with the pyglet.app.run() line, and the window class comes with various functions for handling key and mouse input. I have a number of examples I could provide if you like. As for your current code you could try this:import pyglet from pyglet.window import key import accessible_output2.outputs.auto import time window = pyglet.window.Window() speaker = accessible_output2.outputs.auto.Auto() speaker.speak("test program started") @window.event def on_key_press(symbol, modifiers): speaker.speak("please press space") if symbol == key.SPACE: print('press') speaker.speak("space was pressed") else: speaker.speak("unknown key") print("now sleeping") time.sleep(10) pyglet.app.run() URL: http://forum.audiogames.net/viewtopic.php?pid=268262#p268262 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? What does inconsistent indentation mean?In this code, there is a function. And an if statement in that function, and an eles inside that if. I've decreased 1 indentation level where the else block ends, but it says unindent does not match any outter indentation level. I've never seem this kind of error before. What is the problem in this code?And yes, I wrote this code, just for testing purpose. Is there a better way to write pyglet apps than this one. URL: http://forum.audiogames.net/viewtopic.php?pid=268257#p268257 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? python code needs to be indented properly. i suggest you read this for some help with this. URL: http://forum.audiogames.net/viewtopic.php?pid=268228#p268228 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: a simple python error. How can I solve this?
Re: a simple python error. How can I solve this? Hi,I see where your error is, but that's definitely not the way you write Pyglet apps.Where did you get that code? URL: http://forum.audiogames.net/viewtopic.php?pid=268217#p268217 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
a simple python error. How can I solve this?
a simple python error. How can I solve this? hi all.I would like to ask for help in python.I'm trying to test the pyglet's key event function and when I run the program, I get an indentation error and I don't know when this error means.could someone explain why this error happened?Here goes my stupid codeimport pygletimport accessible_output2.outputs.autoimport timewindow = pyglet.window.Window()key = pyglet.window.key()speaker = accessible_output2.outputs.auto.Auto()speaker.speak("test program started")key_press = window.key_press()def key_press(): speaker.speak("please press space") counter = 0if key.space: speaker.speak("space was pressed") counter = counter+1else: speaker.speak("unknown key") print("now sleeping") time.sleep(10)pyglet.app.run()while counter < 10: key_press() time.sle ep(3) URL: http://forum.audiogames.net/viewtopic.php?pid=268197#p268197 ___ Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector