Setting multiple items to one variable

I have a question about a script with a bunch of if/thens.

if theCar is "red" then
if theCar is "blue" then
if theCar is "yellow" then
if theCar is "green" then
diplay dialog "Great!"
end if
end if
end if

is there a way to do this? I want the the variable theCar to meet multiple requirments…but not have all of the if then statements.

set x to {"red","blue","yellow","green"}
if theCar is x then
display dialog "Great"
end if

A variable can only have one value. However, that value could be a list, or a record.

If the thing you are trying to do is to have the variable “theCar” contain several attributes such as color, model, make, etc., you can make a record variable.

But I am not sure from your example if that is the case. The example seems to suggest that maybe you want to see if the color of the car is IN the list of colors.

If that is the case then


set theColorList to {"red", "green", "blue"}
if theCar is in theColorList then beep -- or whatever

But to make “theCar” a collection of attributes such as a particular color, style, make, model, etc., use a record variable:

set theCar to {color:"red", brand:"Ford", model:"Taurus"}
set color of theCar to "blue"
tell theCar to get its color

etc.

EDIT: and to loop through the cars and look for attributes,


set cars to {{title:"car1", color:"red", brand:"Ford", model:"Taurus"}, {title:"car2", color:"blue", brand:"Chevy", model:"z28"}}

set end of cars to {title:"car3", color:"green", brand:"Porsche", model:"911 Targa"}

repeat with car in cars
	if color of car is "green" then display dialog (title of car) & " is green."
end repeat