Hi all,
I wouldn't for the life of me know whether this is a Python error I'm
making, or whether I'm experiencing something specific to pyglet.
Here's the code:
===========================
# Simple scrolling background with pyglet
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
VSYNC = 60.0
SPEED = 4
import pyglet
from pyglet.gl import *
bkg = pyglet.resource.image('bkg.png') # w = 269
window = pyglet.window.Window(width = SCREEN_WIDTH, height =
SCREEN_HEIGHT, vsync = True)
def bkg_scroll():
x = 0
while x<270:
x += 1
yield x
left = bkg_scroll()
def update(dt):
window.clear()
try:
x = left.next()
except StopIteration:
left = bkg_scroll()
x = left.next()
bkg.blit(-x,0)
bkg.blit(-x+270,0)
bkg.blit(-x+(270*2),0)
bkg.blit(-x+(270*3),0)
pyglet.clock.schedule(update)
pyglet.app.run()
===========================
Running this gives me an error "UnboundLocalError: local variable
'left' referenced before assignment".
Now, removing the try, except code and keeping only:
x = left.next()
makes everything work ok. (Ofcourse, at the end of the iterator, I'm
getting StopIterator errors).
Why does a try..except block make my left variable suddenly unbound?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---