I’ve been bashing my head on this for the past couple hours and I don’t know how to fix it.
I’ve got a function I want to use, and I’m passing a variable into it, a counter to be specific, and I want it to add the counter up, and pass that variable back out, all added up, to be used again the next time I call that function.
The problem is, I’m getting behavior I don’t expect. Here’s a sample of something that works just fine in the blender console
variable = 1 def rimGeometryGenerator(var1): global variable variable = variable + 2 print(variable) rimGeometryGenerator(variable) rimGeometryGenerator(variable) rimGeometryGenerator(variable)
That spits out the answer of 3, 5 and 7 as you would expect, as variable is updated each time the function runs.
However, in my actual code, I’m getting an error saying my variable is not defined. The code snippet looks like this;
def RimGeometryGenerator(iL, posX, posY, posZ): #global indexLocation verts.append([ #index n posX, posY, posZ ]) iL = iL +1 #indexLocation = indexLocation +1 for index in range(self.subs): indexY = (index +1) *2 indexZ = indexY +2 verts.append([ #index for center triangle circle posX, math.sin(math.radians((spin/self.subs)*(index +1)))*posZ, math.cos(math.radians((spin/self.subs)*(index +1)))*posZ, ]) iL = iL +1 #indexLocation = indexLocation +1 faces.append([((iL - self.subs) -1),((iL - self.subs) -2),(iL -1),(iL)]) RimGeometryGenerator(indexLocation, rimX, 0, rimZ) RimGeometryGenerator(indexLocation, rimXBack, 0, rimZ)
indexLocation, which I have commented out right now, already exists and works up to this point, as it’s counting up some stuff before this particular function is called. I’ve tried placing
global indexLocation elsewhere in the code to no avail. To me this looks like I’m doing the same thing as the simple code in the first example, but it’s just not working. Halp?