AppleScript:在值大于 0 之前不要让用户继续

AppleScript: Don't let the user continue until the value is greater than 0

我试图让用户输入 X 个东西的数量,但这些东西不能低于 0,如果用户输入超过 32 个,代码应该 wanrn 用户但仍然允许如果选择继续。

这是我目前的代码:

set aerender_clone to 0
set USER_instances to 0

repeat until USER_instances ≥ 1
    set USER_instances to the text returned of (display dialog "Render instances" default answer 1 with icon note buttons {"Cancel", "Continue"} default button "Continue")
    if USER_instances < 0 then
        display dialog "Atleast 1 instance must be selected" with icon note buttons {"sure, ok"} default button "sure, ok"
    else if USER_instances > 32 then
        display dialog "We recomend a maximum of 32, still want to continue?" with icon note buttons {"No", "Yes"} default button "No"
        set USER_instances to 0
    else
        display dialog "Code is working!"
        set aerender_clone to USER_instances
    end if
end repeat

问题是,如果我输入 4、8、6 之类的数字,代码会一直警告我我的数字大于 32,但如果我输入 12,代码会继续。

我有点迷路了。

您需要使用 as number:

USER_instances 变量设置为实际数值
set USER_instances to the text returned of (display dialog "Render instances" default answer 1 with icon note buttons {"Cancel", "Continue"} default button "Continue") as number

在声明末尾添加 as number 后比较应该可以进行。

如果有人需要它,现在这是正确的代码,感谢 l'L'l answser。

set aerender_clone to 0 as number
set USER_instances to 0 as number

set UserOptions to {yes, no}
set USERcanContinue to no

repeat until USERcanContinue contains yes
    repeat until USER_instances is greater than 0
        set USER_instances to (the text returned of (display dialog "Render instances" default answer 1 with icon note buttons {"Cancel", "Continue"} default button "Continue")) as number
        if USER_instances is less than 1 then
            display dialog "Atleast 1 instance must be selected" with icon note buttons {"sure, ok"} default button "sure, ok"
        else
            -- skip
        end if
    end repeat

    if USER_instances is greater than 32 then

        display dialog "We recomend a maximum of 32, still want to continue?" with icon note buttons {"No", "Yes"} default button "No"
        if button returned of result = "No" then
            set USERcanContinue to no
            set USER_instances to 0 as number
        else
            if button returned of result = "Yes" then
                set USERcanContinue to yes
            end if
        end if
    else
        set USERcanContinue to yes
    end if
end repeat

set aerender_clone to USER_instances