1

我一直在玩applescript,我正在制作一个文本版本的口袋妖怪。我有一个从列表中选择和一个 if 语句来启动一个显示对话框。当你按下运行它应该说“你不能从训练家战斗中逃跑”,但显示对话框永远不会打开。我看不出有什么问题。我一直在搜索谷歌,但找不到解决方案

这是代码

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
4

1 回答 1

2

好的,我发现了问题。

这行错了,去掉 { }: (否则你是把choose from list的return推到一个list中,return已经是一个list了)

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”替换为“Bag”)

那么完整的代码是:

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
于 2013-08-07T09:24:32.273 回答