questions about variables in update() #309
Unanswered
JacktheFabricRipper
asked this question in
Q&A
Replies: 1 comment
-
Read about global variables and scope. Basically you can't assign to a variable outside of a function unless it's global. Something like player.y -= gravity would work however, since it belongs to an object. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to make my own 2d platformer controller, and I'm using variables within my update function. Whenever I try it gives me this error:
Traceback (most recent call last):
File "C:\Users\18019\AppData\Local\Programs\Python\Python39\lib\site-packages\ursina\main.py", line 129, in _update
main.update()
File "C:\Users\18019\OneDrive\Desktop\Parkour\Parkour.py", line 14, in update
playery = playery - gravity * time.dt
UnboundLocalError: local variable 'playery' referenced before assignment
Traceback (most recent call last):
File "C:\Users\18019\OneDrive\Desktop\Parkour\Parkour.py", line 30, in
app.run()
File "C:\Users\18019\AppData\Local\Programs\Python\Python39\lib\site-packages\ursina\main.py", line 238, in run
super().run()
File "C:\Users\18019\AppData\Local\Programs\Python\Python39\lib\site-packages\direct\showbase\ShowBase.py", line 3325, in run
self.taskMgr.run()
File "C:\Users\18019\AppData\Local\Programs\Python\Python39\lib\site-packages\direct\task\Task.py", line 541, in run
self.step()
File "C:\Users\18019\AppData\Local\Programs\Python\Python39\lib\site-packages\direct\task\Task.py", line 495, in step
self.mgr.poll()
File "C:\Users\18019\AppData\Local\Programs\Python\Python39\lib\site-packages\ursina\main.py", line 129, in _update
main.update()
File "C:\Users\18019\OneDrive\Desktop\Parkour\Parkour.py", line 14, in update
playery = playery - gravity * time.dt
UnboundLocalError: local variable 'playery' referenced before assignment
I (think) understand the issue, but I was just wondering if there is a workaround, or if I just can't use variables in update?
Beta Was this translation helpful? Give feedback.
All reactions