2013-08-07 62 views
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 
+1

哦,我使用AppleScript搞亂,並計劃做文字口袋妖怪太:DI才發現這個問題,通過搜索「的AppleScript按鈕」 –

回答

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 

(但如果你想顯示的對話框如果按袋就應該更換「運行」與「袋」)

完整的代碼則是:

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 
+0

哦對不起我的問題犯了一個錯誤它應該運行不包。謝謝您的幫助 – Qwertie

相關問題