NameError: x

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stuart James
    New Member
    • Nov 2010
    • 2

    NameError: x

    This problem is occurring in Jython:

    Code:
    File "<iostream>", line 0, in execute
    NameError: x
    Code:
    class test(cycleevent):
    	x = 100
    	def execute(a, b):
    		global x
    		x -= 1
    		player.sendMessage("testing....")
    		if x == 0:
    			b.stop()
    def stop(a):
    	return
    Why is it throwing this? cycleevent being a Java abstract class.
  • Stuart James
    New Member
    • Nov 2010
    • 2

    #2
    Fixed it myself! Completely new to Python...

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      The answer is in Python scoping rules. The global namespace for a function is always the module in which the function is defined. In your case you can directly access the variable with the dot operator: test.x -= 1

      Comment

      Working...