Hi there. Yesterday That i was trying to do some simple stuff with libaudioverse, I found out if I use the += operater, Handling key presses will faile. I used pyglet to handle them and make the window. So does anyone know what is the reason and how can it be done?
I use C# to develop stuff but since i heard the libaudioverse's HRTF pannings and environment creater, I surprized and since i got some experiences in python i decided to give it try,

Thumbs up

In what way are you using the += operator? Do you get error messages, or does it just not work?

Thumbs up

I don't get any errors at all! Application runs correctly, Just if I have a += oprater in a key press if condition block, Other key press conditions won't work too. My code is here:
import pyglet
import libaudioverse
import time
import sys
import Tolk
libaudioverse.initialize()
from pyglet.window import key
Tolk.load()
window=pyglet.window.Window()
server=libaudioverse.Server()
#Let's have a buffer here
buffer=libaudioverse.Buffer(server)
#now we load a file to use later
buffer.load_from_file("sound.ogg")
#Now the buffernode
bp=libaudioverse.BufferNode(server)
#Now we tell our buffernode what is its buffer
bp.buffer=buffer
#Buffernode looping
bp.looping=True

#Now initialize a panner
e=libaudioverse.EnvironmentNode(server, "default")
e.panning_strategy=libaudioverse.PanningStrategies.hrtf
e.output_channels=2
e.connect(0, server)

o=libaudioverse.SourceNode(server, e)
bp.connect(0, o, 0)

server.set_output_device("default")
e.orientation = 0, 1, 0, 0, 0, 1
e.position.value=(0, 0, 0)
global x
global y
global z

@window.event
def on_key_press(symbol, modifiers):
    if symbol == key.C:
        Tolk.output("%d, %d, %d" %(x, y, z))
    elif symbol == key.w:
        x+=1
    elif symbol == key.Q:
        sys.exit()
@window.event
def on_draw():
    window.clear()

pyglet.app.run()

Thumbs up

4 (edited by magurp244 2017-08-12 08:10:11)

The "W" in "elif symbol == key.w:" isn't capitalized, this is likely causing an error thats blocking any further if statements.

Thumbs up

5 (edited by kianoosh 2017-08-12 12:20:55)

Oh maybe i wrongly did that but anyways, last time it was correct spelled and capitalised but my problem was still there...

Thumbs up

6 (edited by magurp244 2017-08-12 23:56:23)

You'd be surprised at just how often a typo or something stupid like that can trip up even the most experienced programmer for hours on end. Hm, another possibility might be your use of globals, you usually have to specify globals when using them inside functions because of the local/non-local way python handles variables, are you using python 2.x or 3.x?

server.set_output_device("default")
e.orientation = 0, 1, 0, 0, 0, 1
e.position.value=(0, 0, 0)

x = 0
y = 0
z = 0

@window.event
def on_key_press(symbol, modifiers):
    global x
    global y
    global z
    if symbol == key.C:
        Tolk.output("%d, %d, %d" %(x, y, z))
    elif symbol == key.W:
        x+=1
    if symbol == key.Q:
        sys.exit()
@window.event
def on_draw():
    window.clear()

pyglet.app.run()

Thumbs up

7 (edited by kianoosh 2017-08-13 18:14:34)

Fixed. Man that fixed! Oh yeh thanks maggerb sorry for my damn spelling but changing the global's position fixed my problem! Oh maaan!

Thumbs up

do not use globals. They are bad, tigers will steal your children and your head will combust.

Thumbs up