We are trying to get a While Loop to work comparing two variables, but we are getting name errors. Here’s my code: if dept == 928:
y = 6
else:
y = 21
x = 1
while x < y:
print x
x = x + 1
Any idea why the script is getting a “NameError”?
What line are you getting the NameError? Can you post the stack trace and the code?
What variable does the script say is getting a NameError on? Is “dept” declared somewhere before this code?
The NameError is on the “While” line - it doesn’t like our variable. We’ve tried “y”, “z”, “var”, etc. and it just doesn’t like it.
That same script you posted worked for me. Do you have a different script?
Here’s the stack trace:
Traceback (innermost last):
File “event:keyTyped”, line 11, in ?
NameError: y
and here’s the code:if event.keyChar == "\n":
dept = event.source.parent.parent.getComponent("Title Department").Dept
work = event.source.parent.parent.getComponent("Title Department").WC
text = event.source.text
if work != '':
if dept == 928 and work == 18:
y = 6
elif dept == 928 and work == 64:
y = 21
x = 1
while x < y:
if x < 10:
bc = system.tag...
else:
bc = system.tag...
x = x + 1
Ok well that changes the picture. It looks like you are not getting in either if statement to set the y variable. Add this line above the if dept == 928 and work == 18:y = 0
That will fix it.
Thanks Travis!