Simple question about if/then and "or"

Hi guys

Take a look to this script

set {c} to {text returned} of (display dialog "input" default answer "")

if c is "1" or "2" then  -- important
	display dialog "true"
else
	display dialog "false"
end if

Why if the input is “2” script give me “false”?
I put “or” in the if/then, not “and”

I’m on a 10.5.3
Regards

Matteo

Model: iMac 24
AppleScript: 2.2
Browser: Camino 1.6.1
Operating System: Mac OS X (10.5)

Each element of an OR statement must itself be boolean: if c is “1” or c is “2” is the form you want.

set {c} to {text returned} of (display dialog "input" default answer "")

if c is "1" or c is "2" then -- important
	display dialog "true"
else
	display dialog "false"
end if

Tnx for quckly answer.
In fact, now the script works.

But all is bored: does exist a short for to put it?

Try something like this:

display dialog "" default answer ""
set example to text returned of result

if example is in {"1", "2"} then
	display dialog "true"
else
	display dialog "false"
end if

.

Nitpick: I think you’re coercing a record to a list there. One-line alternatives would include:

set c to text returned of (display dialog "input" default answer "")
set {text returned:c} to (display dialog "input" default answer "")

Or, in this instance, of course: :slight_smile:

set c to text returned of (display dialog "input" default answer "")

display dialog ((c is in {"1", "2"}) as text)

In that instance, you could remove the variable and use one line instead. :stuck_out_tongue:

:lol:

And it turns out that the explicit coercion to text isn’t necessary either:

display dialog ((display dialog "input" default answer "")'s text returned is in {"1", "2"})

One that Kai would have enjoyed. :slight_smile: