Hi,
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:
cube1.setPosition([c1pos[0]+xdist1*cspeed,c1pos[1]+ydist1*cspeed,c1pos[2]+zdist1*cspeed])
if own.c1cam==1:
cube1.setPosition(cam1pos)
if own.c2cam==0:
own.c1cam = 0
cube2.setPosition([c2pos[0]+xdist2*cspeed,c2pos[1]+ydist2*cspeed,c2pos[2]+zdist2*cspeed])
if own.c2cam==1:
cube2.setPosition(cam1pos)
own.c2cam = 0
if own.c3cam==0:
cube3.setPosition([c3pos[0]+xdist3*cspeed,c3pos[1]+ydist3*cspeed,c3pos[2]+zdist3*cspeed])
if own.c3cam==1:
cube3.setPosition(cam1pos)
own.c3cam = 0
if own.c4cam==0:
cube4.setPosition([c4pos[0]+xdist4*cspeed,c4pos[1]+ydist4*cspeed,c4pos[2]+zdist4*cspeed])
if own.c4cam==1:
cube4.setPosition(cam1pos)
own.c4cam = 0
if own.c5cam==0:
cube5.setPosition([c5pos[0]+xdist5*cspeed,c5pos[1]+ydist5*cspeed,c5pos[2]+zdist5*cspeed])
if own.c5cam==1:
cube5.setPosition(cam1pos)
own.c5cam = 0
e.t.c.
####################
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]
e.t.c.
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
####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 .
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
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 ???..
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. :-?