FazBear Posted May 19, 2009 Posted May 19, 2009 Hi All Is it possible to control multiple commands from a single if statement? ie. (if (or (= [var1] T) (= [var2] T) (= [var3] T)) (command "circle" "0,0" "25") (command "circle" "0,0" "50") (command "circle" "0,0" "75") (command "circle" "0,0" "100") (command "circle" "0,0" "125") (command "circle" "0,0" "150") (command "circle" "0,0" "175") (command "circle" "0,0" "200") (command "circle" "0,0" "225") (command "circle" "0,0" "250") );end if I have had a play with the (cons & (cond assuming these are allowing the above but cant get it running properly. Can anyone please advise? Thank you. Quote
wizman Posted May 19, 2009 Posted May 19, 2009 wrap with progn, if any of the expression is true then the whole progn statement executes. (if (or (= [var1] T) (= [var2] T) (= [var3] T)) (progn (command "circle" "0,0" "25") (command "circle" "0,0" "50") (command "circle" "0,0" "75") (command "circle" "0,0" "100") (command "circle" "0,0" "125") (command "circle" "0,0" "150") (command "circle" "0,0" "175") (command "circle" "0,0" "200") (command "circle" "0,0" "225") (command "circle" "0,0" "250") ) ) Quote
Freerefill Posted May 19, 2009 Posted May 19, 2009 Ah, common mistake, I screw it up myself all the time. The structure of the If statement is: (if then else ) Ignoring the italicized text, of course. You'll notice one very important and key aspect: it only allows one command. Using a Condition statement will allow many commands, but If allows only one. You can get around this, however. Encase all your commands in a Progn, like such: (progn <command one> <command two> ... <command banana> ) Quote
Lee Mac Posted May 19, 2009 Posted May 19, 2009 Progn is correct for wrapping multiple expressions, I believe you may be able to get around it like this however: (if (or [var1] [var2] [var3]) (command "circle" "0,0" "25" "circle" "0,0" "50" "circle" "0,0" "75" "circle" "0,0" "100""circle" "0,0" "125""circle" "0,0" "150" "circle" "0,0" "175""circle" "0,0" "200""circle" "0,0" "225" "circle" "0,0" "250")) PS> You don't need to specify (= [var1] T) If [var1] holds any value other than nil, it will return T. Quote
Lee Mac Posted May 19, 2009 Posted May 19, 2009 Some more help on Progn here http://www.cadtutor.net/forum/showpost.php?p=173196&postcount=10 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.