我已经玩了一段时间的AppleScript,我正在制作口袋妖怪的文字版本。我有一个从列表中选择和一个if语句来启动显示对话框。当你按Run时它应该说“你不能从训练师的战斗中跑”但显示对话框永远不会打开。我看不出有什么问题。我一直在搜索谷歌但无法找到解决方案
这是代码
set userStarter to "undefined"
set starterHP to "undefined"
set starterLV to 5
set starters to {"Charmander", "Bulbasor", "Squirtle", "Pikachu"}
set userName to "undefined"
on battle(traner)
display dialog traner & " wants to battle!" buttons {"Next"}
set battleMenu to {"Attack", "Bag", "Run"}
set temp to {choose from list battleMenu}
if temp is "Run" then
display dialog "You cannot run from a trainer battle" buttons {"Ok"}
end if
end battle
display dialog "Welcome to text based Pokemon!" buttons {"Play", "Quit"}
if the button returned of the result is "Play" then
set temp to display dialog "What is your name?" default answer "Ash" buttons {"Submit"}
set userName to text returned of temp
set userStarter to {choose from list starters}
display dialog "Oak: Okay " & userName & " here is your " & userStarter buttons {"Next"}
display dialog "Gary: Hey, lets battle!" buttons {"Battle"}
battle("Gary")
end if
这是日志
tell application "AppleScript Editor"
display dialog "Welcome to text based Pokemon!" buttons {"Play", "Quit"}
--> {button returned:"Play"}
display dialog "What is your name?" default answer "Ash" buttons {"Submit"}
--> {text returned:"Ash", button returned:"Submit"}
choose from list {"Charmander", "Bulbasor", "Squirtle", "Pikachu"}
--> {"Pikachu"}
display dialog "Oak: Okay Ash here is your Pikachu" buttons {"Next"}
--> {button returned:"Next"}
display dialog "Gary: Hey, lets battle!" buttons {"Battle"}
--> {button returned:"Battle"}
display dialog "Gary wants to battle!" buttons {"Next"}
--> {button returned:"Next"}
choose from list {"Attack", "Bag", "Run"}
--> {"Run"}
end tell
答案 0 :(得分:2)
好的,我发现了问题。
此行错误,删除{} :(否则您将从列表中选择返回到列表中,返回已经是列表)
set temp to {choose from list battleMenu}
然后从列表中选择返回一个列表,所以你必须检查:
if temp is {"Run"} then
display dialog "You cannot run from a trainer battle" buttons {"Ok"}
end if
(但是如果你想按下行李要显示对话框,你应该用“Bag”替换“Run”)
完整的代码是:
set battleMenu to {"Attack", "Bag", "Run"}
set temp to choose from list battleMenu
if temp is {"Run"} then
display dialog "You cannot run from a trainer battle" buttons {"Ok"}
end if