View Full Version : 3d Max Maxscript Essentials Book question
02-13-2011, 02:06 AM
This code produces 7 teapots stacked in x and y
I think I understand it all except why the last (7th) Teapot
has a position in x of 120 yet the boolean while statement
says t.pos.x < 101 why is there a teapot at 120?
Shouldn’t the loop stop at 100 as it is looping every at every
20 units and is under 101?
i = 0
t = teapot pos:[i*20, 0, i*20]
i = i+1
) while t.pos.x < 101
If I edit the code to
while t.pos.x < 100
or even 80 it stops at the correct value
Appreciate any help with this
02-13-2011, 02:16 AM
It happens, because the while is after the execution of the loop. So a teapot will be create at 120, and after creation it will stop, because that last teapot.pos.x was greater than 101. Basically what the while is doing is the following:
0 < 101, yes create another
20 < 101, yes create another
40 < 101, yes create another
60 < 101, yes create another
80 < 101, yes create another
100 < 101, yes create another
120 < 101, no it's greater don't create any more
02-13-2011, 02:25 AM
ok thanks Eric that makes sense
A do-while loop is often used where you want something to run at least once. For example, were you writing a script or program where you wanted something to repeat until the user wanted to quit, you'd do something like,
messageBox "Hello my friend." beep:false
However, for-loops are much more preferred when you do not need such functionality. :)
02-14-2011, 09:35 PM
Thanks Jonathan very helpful.
My brain got stuck trying to understand this section in the book and I couldn't resolve it. The simple answer from Eric got me back on track and your example gave it context.
The book seems ok but seems to be more of an intermediate level book that revisits some of the basics but without lengthy explanations.
Not sure if it's the medication or the late nights or if I'm not suited to programming but.......... :banghead: it will be made to enter the brain one way or another. ;)
02-14-2011, 09:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.