2016-11-07 96 views
0

你好,我试图让这个代码工作,但Blurb执行后它说它不知道Blob。所以我认为我只需要把Blob放在开头,但Blob不知道Blurb等等。 如果所有答案都正确,则命令为Blob,Blurb,Blirb,Blorb,Blarb并完成。我该如何做这项工作? (applescript)

script finish 
set dialogResult to display dialog ¬ 
    "Can you escape?" buttons "Cool!" 
end script 

script Blarb 
set dialogResult to display dialog ¬ 
    "Can you escape?" buttons {"No", "Yes"} 
if button returned of dialogResult = "Yes" then 
    run script Blob 
end if 
end script 

script Blorb 
set dialogResult to display dialog ¬ 
    "Can you escape?" buttons {"No", "Yes"} 
if button returned of dialogResult = "No" then 
    run script Blob 
else if button returned of dialogResult = "Yes" then 
    run script Blarb 
end if 
end script 

script Blirb 
set dialogResult to display dialog ¬ 
    "Can you escape?" buttons {"No", "Yes"} 
if button returned of dialogResult = "No" then 
    run script Blob 
else if button returned of dialogResult = "Yes" then 
    run script Blorb 
end if 
end script 

script Blurb 
set dialogResult to display dialog ¬ 
    "Can you escape?" buttons {"No", "Yes"} 
if button returned of dialogResult = "Yes" then 
    run script Blob 
else if button returned of dialogResult = "No" then 
    run script Blirb 
end if 
end script 

script Blob 
set Variable to "No" 
repeat while Variable = "No" 
    set dialogResult to display dialog ¬ 
     "Can you escape" buttons {"No", "Yes"} 
    set Variable to button returned of dialogResult 
    if button returned of dialogResult = "Yes" then 
     run script Blurb 
    end if 
end repeat 
end script 



run script Blob --Order if all answers are correct is Blob, Blurb, Blirb, Blorb, Blarb, and finish. 

回答

0
  1. 一般的建议:不要使用run script NAME;这里是run NAME就足够了。 (run script创建一个全新的AS解释器实例,并将脚本发送到该脚本中运行)。它还可以让您准确查看错误发生的位置。

  2. 这里的问题是,AppleScript编译器是一个废话。静态绑定的变量名称需要在使用它们的代码之前声明,否则编译器太愚蠢,无法正确地找到并绑定它们。如果可行,请重新排列脚本对象,以便在使用它们的代码之上声明它们。如果你有循环引用,脚本A引用脚本B,而B引用A,那么这将不起作用。在变量名称之前插入一个my关键字使得AS动态地查找该变量,从而避免了这个特殊问题。 (调用AS子程序总是动态绑定的,所以你不需要担心这些。)

  3. 不要发布示例代码,要求人们强制退出脚本编辑器以摆脱它。这很烦人,不会让你有任何朋友。

+0

好吧,对不起,我是applescript的noob,所以我会搜索如何使用“我的”关键字。 – JulesTheGodOfMC

+0

将所有'运行脚本Blob'命令更改为'运行我的Blob','运行脚本Blirb'以'运行我的Blirb'等 – foo

+0

哦,并学会使用AppleScript for Good,而不是Evil。老实说,这已经足够邪恶了。 – foo