Notifications
Clear all
[Closed] Nested "for" Loops & Using Variables for Parameters
Page 2 / 2
Prev
Jul 30, 2008 5:49 pm
A little code clean up, you can remove everything (but the format) in the unsupplied loop. Once it gets here you already know that the parameter is unsupplied so you can just jump to the format.
fn updateMyBox l: w: h: =
(
argArray = #(l,w,h)
paramArray = #("length","width","height")
for i = 1 to argArray.count do
(
if argArray[i] == unsupplied then
(
format "-- % unchanged - new value unsupplied.
" paramArray[i]
)
else
(
setProperty mybox paramArray[i] argArray[i]
format "++ % set to %.
" paramArray[i] argArray[i]
)
)
)
-Eric
Jul 30, 2008 5:49 pm
Hey Gavin,
I tried using "undefined" instead of "unsupplied" in the function, but when I do the script errors when all of the arguments are not supplied. For example, when the argument "h" is not specified within the function call, the value of "h" within the function reads as "unsupplied". In that case the function scripted using "undefined" returns the error:
"-- Unable to convert: unsupplied to type: Float"
So it seems to me that this type of argument check requires the use of "unsupplied" rather than "undefined", unless I am missing something else. (which is entirely possible) I would rather us "undefined" for consistency as well, but it seems to break things here.
Eric,
Gotcha... thank you very much. Eliminating the unneeded code certainly cleans things up a bit. =)
Thank you again guys. All of your help is really appreciated.
Cheers,
Dave
Jul 30, 2008 5:49 pm
As he mentioned you need to define the default parameter as undefined. Whatever is placed after the variable declaration colon (var:<default>) becomes the default value, which if the value is unsupplied it is replaced by the default.
fn updateMyBox l:undefined w:undefined h:undefined
-Eric
Jul 30, 2008 5:49 pm
Ahhh… see… there I go missing the obvious again. =) Thank you Eric, for clarifying the point that Gavin was making. I’m sorry I missed that. You’ve all been a terrific help; I understand several things better now. Thanks again.
Cheers,
Dave
Page 2 / 2
Prev