Jump to content

Combine IF


FazBear

Recommended Posts

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.

Link to comment
Share on other sites

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")

)

)

Link to comment
Share on other sites

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>
 )

Link to comment
Share on other sites

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.

 

:P

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...