简体   繁体   English

未定义变量结果AppleScript

[英]The variable result is not defined AppleScript

I am working on the same app that I mentioned in my first question. 我正在使用第一个问题中提到的同一应用程序。 I have gotten much farther, but when I try to play "2048" the first time, AppleScript give me the error: 我走得更远,但是当我第一次尝试播放“ 2048”时,AppleScript给了我错误:

"The variable result is not defined"

I will skip the main bulky body of the app and get to the area with the problem: 我将跳过该应用程序的主要主体,并转到出现问题的区域:

display dialog "What would you like to do?
    Sleep = Go to sleep
    Finder = Open Finder
    Time = Display current time and date
    2048 = play 2048
    Quit = Quit application" default answer "" with title "Control panel"
if the text returned of the result is "Sleep" then
    tell application "System Events" to sleep
    display dialog "Hello, welcome back!" buttons {"Thank you!"} default button 1
    return
else if the text returned of the result is "Finder" then
    tell application "Finder" to make new Finder window
else if the text returned of the result is "Time" then
    set a to (current date) as list
    set AppleScript's text item delimiters to linefeed
    set a to a as text
    display dialog a buttons {"OK"} default button 1
else if the text returned of the result is "Quit" then
    return
else if the text returned of the result is "2048" then
    tell application "Terminal"
            do script "/Users/student/Documents/2048.sh"
            activate
    end tell
else
    display dialog "Invalid response" with title "Invalid response" buttons {"Go back", "Quit"} default button 1
end if
if the button returned of the result is "Go back" then
    display dialog "What would you like to do?
    Sleep = Go to sleep
    Finder = Open Finder
    Time = Display current time and date
    2048 = play 2048
    Quit = Quit application" default answer "" with title "Control panel"
else
    return
end if
if the text returned of the result is "Sleep" then
    tell application "System Events" to sleep
    display dialog "Hello, welcome back!" buttons {"Thank you!"} default button 1
    return
else if the text returned of the result is "Finder" then
    tell application "Finder" to make new Finder window
else if the text returned of the result is "Time" then
    set a to (current date) as list
    set AppleScript's text item delimiters to linefeed
    set a to a as text
    display dialog a buttons {"OK"} default button 1
else if the text returned of the result is "Quit" then
    return
else if the text returned of the result is "2048" then
    tell application "Terminal"
            do script "/Users/student/Documents/2048.sh"
            activate
    end tell
end if

Just set the result of the display dialog to a variable and use the variable. 只需将显示对话框的结果设置为变量,然后使用该变量即可。 It's tricky to use "result" as you have in many if statements. 像在许多if语句中一样使用“结果”是很棘手的。 One of them is bound to cause a problem because "result" will change at some point. 其中之一注定会引起问题,因为“结果”将在某个时候发生变化。

So do something like this right after your display dialog statement... 因此,在显示对话框语句之后立即执行类似的操作...

set {buttonReturned, textReturned} to {button returned of result, text returned of result}

Then in your if statements use buttonReturned or textReturned. 然后在您的if语句中使用buttonReturned或textReturned。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM