Condensing Code

I have lot of code and i would like to make it smaller with the len and range function but am a bit perplexed. Using this will it run any quicker or is it just easier to type??? heres my code which i would like to be amller could you please help…

if own.c1cam==0:
if own.c1cam==1:

if own.c2cam==0:
	own.c1cam = 0	
if own.c2cam==1:
	own.c2cam = 0
if own.c3cam==0:
if own.c3cam==1:
	own.c3cam = 0
if own.c4cam==0:
if own.c4cam==1:
	own.c4cam = 0	

if own.c5cam==0:
if own.c5cam==1:
	own.c5cam = 0


xdist1 = e1pos[0]-c1pos[0]
ydist1 = e1pos[1]-c1pos[1]
zdist1 = e1pos[2]-c1pos[2]

xdist2 = e2pos[0]-c2pos[0]
ydist2 = e2pos[1]-c2pos[1]
zdist2 = e2pos[2]-c2pos[2]

xdist3 = e3pos[0]-c3pos[0]
ydist3 = e3pos[1]-c3pos[1]
zdist3 = e3pos[2]-c3pos[2]

xdist4 = e4pos[0]-c4pos[0]
ydist4 = e4pos[1]-c4pos[1]
zdist4 = e4pos[2]-c4pos[2]


Thanks, also does anyone have any ideas on making number have less numbers after the decimal place i tried something like %2f% but i think this might be for strings rather than numbers


####put the properties into a list

camList = []
camList.append(own.c2cam) etc

####then if you’re using a for loop, you use an index… like so

for index in camList:
if index==1: cube1.setPosition(posList[index])

###you’d need to build a seperate list called posList to use this method of course.

###So these are some general ideas. of how to use a forloop. neither method is significantly more efficient, loops are more tidy, but you do need to build lists, perhaps with an init part of your script you only run once. Note i didn’t look deep into your code, i hope you were just asking how to use a for loop in this sort of situation to make less code

Thanks abracsis, i thought that by using a for loop my program would run more effecierntly, but now i guesss i dont have to recode everything so thanks for the answer- lots less work for me :smiley: .

Any ideas about turning floats with lots of numbers after the . in ones with less i.e 3.232321241245 into 3.23 e.t.c

%2f % ???


удаляйте :wink:

You the […]! Write about my game comments. You think, so it was easy to create to me it?
I have asked you \ "LEAVE the COMMENT \ ".
you will […] Differently ???..

The […], show, that you have made on Blender?

You the […]! Write about my game comments. You think, so it was easy to create to me it?
I have asked you \ "LEAVE the COMMENT \ ".
you will […] Differently ???..

The […], show, that you have made on Blender?

[edited by moderator: jd-multi, because of bad words useage]

If you have a problem, it would be better to send a moderator about it, and let hem deal with the problem. It’s not allowed to reply a post and curse someone straight on the topic. Next time drop a PM to me.

I hope you understand de reason why i edited your post. :-?

whats that all about??? the code is taken from:

whats the problem?