Lost Adventurer, Aleks Kirilenko (3D)
LC #42 Pipers Alley

View Full Version : 3d Max Maxscript Essentials Book question

02-13-2011, 03: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, 03: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, 03:25 AM
ok thanks Eric that makes sense

02-14-2011, 12:59 PM
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
while (querybox("Continue?"))
print "Done."

However, for-loops are much more preferred when you do not need such functionality. :)

02-14-2011, 10: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. ;)

CGTalk Moderation
02-14-2011, 10: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.