我正在创建一个非常基本的AppleScript,其中包含类似于魔法8球的东西......但是当我输入一个数字时,例如,answer2是该人输入的数字,并根据你的结果出现的数字。当我输入任意数字时,会出现两个对话框。这是为什么?
if answer2 is less than 3 then display dialog "My sources say yes"
if answer2 is greater than or equal to 3 and answer2 is less than or equal to 6 then display dialog "There's a 65% chance of it happening"
if answer2 is greater than or equal to 7 and answer2 is less than or equal to 9 then display dialog "Ask me again later"
if answer2 is greater than or equal to 10 and answer2 is less than or equal to 13 then display dialog "Yes, as sure as the sky is blue!"
if answer2 is greater than or equal to 14 and answer2 is less than or equal to 15 then display dialog "My reply is no"
if answer2 is greater than or equal to 15 and answer2 is less than or equal to 17 then display dialog "Outlook not so good"
if answer2 is greater than or equal to 18 and answer2 is less than or equal to 20 then display dialog "Signs point to yes"
if answer2 is greater than or equal to 20 and answer2 is less than or equal to 23 then display dialog "You can rely on it"
if answer2 is greater than or equal to 24 and answer2 is less than or equal to 25 then display dialog "Not in a million years!"
if answer2 is greater than or equal to 26 and answer2 is less than or equal to 28 then display dialog "I better not tell you now"
if answer2 is greater than or equal to 29 and answer2 is less than or equal to 32 then display dialog "Concentrate and then ask me again"
if answer2 is greater than or equal to 33 and answer2 is less than or equal to 35 then display dialog "My sources say no"
if answer2 is greater than or equal to 36 and answer2 is less than or equal to 39 then display dialog "You will have to wait"
if answer2 is greater than or equal to 40 and answer2 is less than or equal to 43 then display dialog "Don't bet on it"
if answer2 is greater than or equal to 44 and answer2 is less than or equal to 45 then display dialog "You can forget about it"
if answer2 is greater than or equal to 46 and answer2 is less than or equal to 47 then display dialog "There is a better change of snow in the Sahara"
if answer2 is greater than or equal to 48 and answer2 is less than or equal to 50 then display dialog "I am laughing very hard, you better ask again"
if answer2 is greater than or equal to 51 and answer2 is less than or equal to 53 then display dialog "The sky is blue, the grass is green, and your answer is yes!"
if answer2 is greater than or equal to 54 and answer2 is less than or equal to 57 then display dialog "Very doubtful"
if answer2 is greater than or equal to 58 and answer2 is less than or equal to 60 then display dialog "Not in a million years"
if answer2 is greater than or equal to 61 and answer2 is less than or equal to 63 then display dialog "I can't decide"
if answer2 is greater than or equal to 64 and answer2 is less than or equal to 67 then display dialog "Just google it! "
if answer2 is greater than or equal to 68 and answer2 is less than or equal to 70 then display dialog "I don't think so"
if answer2 is greater than or equal to 71 and answer2 is less than or equal to 73 then display dialog "The answer is coming to me..just one more second.. sorry I lost it "
if answer2 is greater than or equal to 75 and answer2 is less than or equal to 78 then display dialog "Don't ask"
if answer2 is greater than or equal to 79 and answer2 is less than or equal to 80 then display dialog "I have no idea"
if answer2 is greater than or equal to 81 and answer2 is less than or equal to 84 then display dialog "Sorry, out of psychic coverage range "
if answer2 is greater than or equal to 85 and answer2 is less than or equal to 88 then display dialog "Highly unlikely"
if answer2 is greater than or equal to 89 and answer2 is less than or equal to 92 then display dialog "Very likely! "
if answer2 is greater than or equal to 93 and answer2 is less than or equal to 96 then display dialog "I don't think so.. chances are very low"
if answer2 is greater than or equal to 97 and answer2 is less than or equal to 100 then display dialog "The answer is coming to me..just one more second.. sorry I lost it "
答案 0 :(得分:0)
display dialog
返回一个字符串,而不是一个数字。你必须将字符串强制转换为整数
在你的代码前面把它放好。
repeat
set answer2 to text returned of (display dialog "Enter a Number" default answer "0")
try
set answer2 to answer2 as integer
exit repeat
on error
display dialog "I said: Enter a Number" buttons {"Give Up", "Try again"} cancel button 1 default button 2
end try
end repeat
我建议使用if
- else if
- end if
语法以获得更好的效果。