applescript 计算器不工作

applescript Calculator not working

我制作了一个计算器,它应该可以用但不能用。唯一有效的部分是加法。这是我的代码:

   my Calculator()
on Calculator()
    display dialog "Calculator" buttons {"Add", "Multiply", "Divide"}
    if button returned of the result is "Add" then
        display dialog "What plus What?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a + b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
    if button returned of the result is "Multiply" then
        display dialog "What times what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a * b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
    if button returned of the result is "Divide" then
        display dialog "What divided by what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a / b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
end Calculator
end
   end

这是一个applescript代码。对不起,如果这是一个菜鸟问题,但我需要帮助。谢谢!

您正在使用三个 if/end if 语句来处理返回的按钮,您应该只使用一个 if/end,并在中间使用 else if。我已经编辑了你的代码来修复它,并注释掉了不正确的区域。

例如:

   my Calculator()
on Calculator()
    display dialog "Calculator" buttons {"Add", "Multiply", "Divide"}
    if button returned of the result is "Add" then
        display dialog "What plus What?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a + b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    else if button returned of the result is "Multiply" then
        display dialog "What times what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a * b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    else if button returned of the result is "Divide" then
        display dialog "What divided by what?" default answer ""
        set a to (text returned of result)
        if a is equal to "q" then
            return
        end if
        display dialog "Next number" default answer ""
        set b to (text returned of result)
        set c to a / b
        display dialog "The answer is " & c buttons {"Start Again", "Quit"}
        if button returned of the result is "Quit" then
            return
        else
            my Calculator()
        end if
    end if
end Calculator
end
   end