struggling with indent errors!

I’m trying to learn some scripting so I thought that a nice simple first step would be to modify an existing material node script. I am “simply” trying to take the 10 way texture switcher and increase it to accept 20 textures:
http://blenderartists.org/forum/showthread.php?t=155800
But every time I make changes I am stimied by indent errors! Here is what I’ve come up with :
http://www.filefront.com/14656425/NodalSwitchBox20f.py

Is there a limit to line length with python scripts or in Pythin itself? Perhaps that is the problem, I don’t know I am getting rather frustrated. I can’t figure out how to post text here and have the indents maintained so I appologize about the double wide screenshots but since you can’t use wordwrap I can think of no other way of showing you where I am getting the errors. First the error message seems to be in the long definition line but doesn’t go away when I shorten it:
http://img242.imageshack.us/img242/4874/20waynodalswitchgerrorm.png

And again sorry for the huge images, the actual script:
http://img101.imageshack.us/img101/2198/20waynodalswitchgleft.png

http://img39.imageshack.us/img39/6219/20waynodalswitchgright.png

and here is the script as text:
#"""
#Name: ‘20Way Nodal Frame Switch’
#Blender: ‘248-249’
#Group: ‘Animation’
#Tooltip: ‘Edit the values in the script below in the section User Definable Variables to work’
#"""
#author = “expanded to 20 textures by Lyle Walsh” “from the 10Way Nodal Frame Switch- written by Holly Tsukiko Grimes”
#url = [“Fairytalecomics, http://www.fairytalecomics.com/”]
#version = “0.96”
#bpydoc = “”\

#Description:
#This is merely an expansion of the 10Way Nodal Frame Switch - which works as a texture multiplexer material node that outputs
#one of 20 textures depending on the frame number. Note each texture must first be saved in a dummy material and set to fake ‘F’
#What follows is the original 10way nodal switch description for version 0.95:

"A nodal version of my script from http://blenderartists.org/forum/showthread.php?t=141472

#This is a simple node that allows one to select a colour/texture/value
#to use in a node map depending on the current frame of the animation i.e
#A 10-way switch based on the current frame.

#This version is simplier, easier to use and customise and can be used
#for any colour or float-value in a node map compared to the original
#script.

#You simply edit the array below to have a range of frames you want that
#‘channel’ of the node to be active. If the current frame isn’t in the array
#the node automatically forwards the ‘Base’ Channel so something is always
#forwarded. The array works in pairs, so you have to set a start frame and an
#end frame (inclusive).

#If you have more than 1 channel indicated for a frame, the switcher only chooses
#the first instance of it eg if channels 3 and 5 are in the array as active for
#frame 32, channel 3 is used.

#Drawbacks: cannot be used in glsl textures or previewing on the fly due to the amount of
#computations needed per pixel. I’m hoping to speed this up in the future.

#There is a glitch in which the texture detail forwarded is corrupt due to poor multithread support
#from python, make sure you only use 1 thread if you wish to use this node.

#Revisions 0.9->0.95: corrected a glitch in which wrong channel is selected due to the indices being
#off in the searcher"
import Blender
from Blender import *
from Blender import Node
######################################################
#User Definable Variables
#Edit these values for your own personalised node
######################################################
#Example array information
#(note: do not change name of array)
#Base= Base texture Colour (not shown but is active on frames 1-10, 211+)
#1= texture 1 active on frames 11-20
#2= texture 2 active on frames 21-30
#3= texture 3 active on frames 31-40
#etc, etc, cycling through the 20 input textures each 10 frames
FrameInfoArray=[
[11,20],
[21,30],
[31,40],
[41,50],
[51,60],
[61,70],
[71,80],
[81,90],
[91,100],
[101,110],
[111,120],
[121,130],
[131,140],
[141,150],
[151,160],
[161,170],
[171,180],
[181,190],
[191,200],
[201,210]]

######################################################
#Main Node class

#Doesn’t need to be changed. Its automatically set up
#for 10 fields, inc the base field, more can be achieved
#but one would need to extend the arrays
######################################################
class FTextureChanger(Node.Scripted):
def init(self, sockets):
colB = Node.Socket(‘TexBase’, val = 4*[1.0])
col1 = Node.Socket(‘Tex1’, val = 4*[1.0])
col2 = Node.Socket(‘Tex2’, val = 4*[1.0])
col3 = Node.Socket(‘Tex3’, val = 4*[1.0])
col4 = Node.Socket(‘Tex4’, val = 4*[1.0])
col5 = Node.Socket(‘Tex5’, val = 4*[1.0])
col6 = Node.Socket(‘Tex6’, val = 4*[1.0])
col7 = Node.Socket(‘Tex7’, val = 4*[1.0])
col8 = Node.Socket(‘Tex8’, val = 4*[1.0])
col9 = Node.Socket(‘Tex9’, val = 4*[1.0])
col10 = Node.Socket(‘Tex10’, val = 4*[1.0])
col11 = Node.Socket(‘Tex11’, val = 4*[1.0])
col12 = Node.Socket(‘Tex12’, val = 4*[1.0])
col13 = Node.Socket(‘Tex13’, val = 4*[1.0])
col14 = Node.Socket(‘Tex14’, val = 4*[1.0])
col15 = Node.Socket(‘Tex15’, val = 4*[1.0])
col16 = Node.Socket(‘Tex16’, val = 4*[1.0])
col17 = Node.Socket(‘Tex17’, val = 4*[1.0])
col18 = Node.Socket(‘Tex18’, val = 4*[1.0])
col19 = Node.Socket(‘Tex19’, val = 4*[1.0])
col20 = Node.Socket(‘Tex20’, val = 4*[1.0])
colO = Node.Socket(‘Colour’, val = 4*[1.0])
ValB= Node.Socket(‘ValueBase’, val = 1.0, min = 0.0, max = 1.0)
Val1= Node.Socket(‘Value1’, val = 1.0, min = 0.0, max = 1.0)
Val2= Node.Socket(‘Value2’, val = 1.0, min = 0.0, max = 1.0)
Val3= Node.Socket(‘Value3’, val = 1.0, min = 0.0, max = 1.0)
Val4= Node.Socket(‘Value4’, val = 1.0, min = 0.0, max = 1.0)
Val5= Node.Socket(‘Value5’, val = 1.0, min = 0.0, max = 1.0)
Val6= Node.Socket(‘Value6’, val = 1.0, min = 0.0, max = 1.0)
Val7= Node.Socket(‘Value7’, val = 1.0, min = 0.0, max = 1.0)
Val8= Node.Socket(‘Value8’, val = 1.0, min = 0.0, max = 1.0)
Val9= Node.Socket(‘Value9’, val = 1.0, min = 0.0, max = 1.0)
Val10= Node.Socket(‘Value10’, val = 1.0, min = 0.0, max = 1.0)
Val11= Node.Socket(‘Value11’, val = 1.0, min = 0.0, max = 1.0)
Val12= Node.Socket(‘Value12’, val = 1.0, min = 0.0, max = 1.0)
Val13= Node.Socket(‘Value13’, val = 1.0, min = 0.0, max = 1.0)
Val14= Node.Socket(‘Value14’, val = 1.0, min = 0.0, max = 1.0)
Val15= Node.Socket(‘Value15’, val = 1.0, min = 0.0, max = 1.0)
Val16= Node.Socket(‘Value16’, val = 1.0, min = 0.0, max = 1.0)
Val17= Node.Socket(‘Value17’, val = 1.0, min = 0.0, max = 1.0)
Val18= Node.Socket(‘Value18’, val = 1.0, min = 0.0, max = 1.0)
Val19= Node.Socket(‘Value19’, val = 1.0, min = 0.0, max = 1.0)
Val20= Node.Socket(‘Value20’, val = 1.0, min = 0.0, max = 1.0)
ValO= Node.Socket(‘ValueOut’, val = 1.0, min = 0.0, max = 1.0)
sockets.input = [ValB,colB,Val1,col1,Val2,col2,Val3,col3,Val4,col4,Val5,col5,Val6,col6,Val7,col7,Val8,col8,Val9,col9,Val10,col10,Val11,col11,Val12,col12,Val13,col13,Val14,col14,Val15,col15,Val16,col16,Val17,col17,Val18,col18,Val19,col19,Val20,col20]
sockets.output = [ValO, colO]

def call(self):
def checkframes(frameno, FrameArray):
Texno=-1
found=0
for Lnum in range(0,len(FrameArray)):
for Fnum in range(0,len(FrameArray[Lnum])/2):
if found==0:
if int(frameno) >= FrameArray[Lnum][(Fnum)*2] and int(frameno) < FrameArray[Lnum][((Fnum)*2)+1]:
Texno=Lnum
found=1
return Texno

scn= Blender.Scene.GetCurrent()
currframe=str(Blender.Get(‘curframe’))
ColourinputArray=[self.input.Tex1, self.input.Tex2, self.input.Tex3, self.input.Tex4,self.input.Tex5,self.input.Tex6,self.input.Tex7,self.input.Tex8,self.input.Tex9,self.input.Tex10,self.input.Tex11,self.input.Tex12, self.input.Tex13, self.input.Tex14,self.input.Tex15,self.input.Tex16,self.input.Tex17,self.input.Tex18,self.input.Tex19,self.input.Tex20]
ValueinputArray=[self.input.Value1, self.input.Value2, self.input.Value3, self.input.Value4,self.input.Value5,self.input.Value6,self.input.Value7,self.input.Value8,self.input.Value9,self.input.Value10,self.input.Value11, self.input.Value12, self.input.Value13, self.input.Value14,self.input.Value15,self.input.Value16,self.input.Value17,self.input.Value18,self.input.Value19,self.input.Value20]
Texnumber= checkframes(currframe, FrameInfoArray)
if Texnumber!=-1:
self.output.Colour = ColourinputArray[Texnumber]
self.output.ValueOut = ValueinputArray[Texnumber]
else:
self.output.Colour = self.input.TexBase
self.output.ValueOut = self.input.ValueBase
node = FTextur eChanger

The problem isn’t the length of the line (python doesn’t care), it’s your indention. The highlighted line does not need to be indented. In python, indention matters. If the previous line doesn’t end in a colon, you can’t increase the indention.

In your script, you just need to delete the indention, make the socket lines line up with the val lines.

PS: Next time, please use smaller pictures, and use the “code” block thing when you enter in long scripts. It’s the pound sign at the top right of the box you type in.

PSS: I really don’t think this is a good beginner’s project. Please see this thread for a better way to start out. http://blenderartists.org/forum/showthread.php?t=168384

Last edit, I promise:
Sometimes python error messages can be pretty cryptic, but in this case, it clearly tells you that the problem was with the indention. So, make sure you read the error messages closely.

Don’t you just hate indent error!

I know I do!!!

I would like to wrangle the person who decided to use TAB indentation as delimiters for logic elements. It is just a waste of time…

Are you being serious? I like using tabs for delimiters.

[quote=marky1991;1482431]
PS: Next time, please use smaller pictures, and use the “code” block thing when you enter in long scripts. It’s the pound sign at the top right of the box you type in.

quote]
Thanks for your help, I’ll give that a try. Also thanks for the advice on the “code” tag, I couldn’t figure out how to put code in myself :o

I am totally serious. I would rather type a semi-colon at the end of each line than to have to rely on TAB based indentation for delimiting it is not cross-platform compatible.

When your scripts get big, it becomes a real problem. Take Lux for instance. I have worked on that source code, but the way it is formatted means every time I try to edit any part of it, I have to spend an hour rippling TAB indentation errors out of the source code. It works fine until you touch it. I’m sure it is related to the way the source code is stored on the server, or some Linux to Windows bug, but let’s face it, it is only a text file. How come I have to face this problem? Because the creators of Python decided on TAB delimitation, that’s why.

I really would like to wrangle that person, imagine Homer Simpson with his hands around Barts neck. Now shake it hard and shake it hard. Replace Bart in your mind with the creator of Python TAB delimitation. Hold that in your mind. Ahh…now I feel like I have got something done today.

python follows outlineing style organization we all learned in school. and python actually prefers space indentation to tabs. python even includes a script that will convert tabs to spaces, but if you are putting in unneeded spaces it wont help in that situation. on the bright side the console does tell you where the problem is and what the problem is.

Sounds like exactly “just some linux to window thing”. I’ve seen this with misinterpreted text encodings. A decent text editor should be able to detect the correct encoding, or at least let you select how to interpret the file. Textwrangler, which I use on the Mac, does this. In some cases, I’ve given up on fiddling with the interpretation, and have resorted to find + replace all the “wrong” tabs into proper ones. Takes all of twelve seconds.

I really would like to wrangle that person, imagine Homer Simpson with his hands around Barts neck. Now shake it hard and shake it hard. Replace Bart in your mind with the creator of Python TAB delimitation. Hold that in your mind. Ahh…now I feel like I have got something done today.

If it’s any consolation, I’ve often felt that way about the TV tech that came up with the concept of fields. I’m happy that that’s on its way out.

Still, spaces not tabs are what you should use, at least according to the Python style guide.

Well this is frustrating - as soon as I fix one indent problem another “xx not defined” pops up due to another indent problem, sheesh this is the 6th indent error I’ve found now, I need to print this out by hand and circle all the levels of indent I guess so that I can figure out everything that is wrong. That’s what I get for using someone elses code, I don’t have a feel for python yet.

So what do you reccomment for a Python editor for windblows?

I use programmers notepad:
http://www.pnotepad.org/download/

There is also:
http://www.scintilla.org/SciTE.html