Lua脚本中的if-else块

我正在尝试在Lua脚本中创建一个if-else语句。但我真的无法让它正常工作:(这是我拥有的东西。

首先我有一个随机器可以在一些计划之间进行选择

local phones_priceplan = {
    { priceplan = 'Fast'},
    { priceplan = 'Mini'},
    { priceplan = 'kort'},
}
local rnd_priceplan     =   math.random(1, #phones_priceplan)
local priceplan         =   phones_priceplan[rnd_priceplan]['priceplan']

然后如果priceplan等于**'Fast'**,我想要运行另一个随机器

if priceplan == "Fastpris"
    local fastpris_plan = {
        {   price = '145',  gb = '0.5', },
        {   price = '195',  gb = '2',   },
        {   price = '245',  gb = '6',   },

    }
    local rnd_phone_surf_plan       =   math.random(1, #fastpris_plan)
    local surf_price            =   fastpris_plan[rnd_phone_surf_plan]['surf_price']
end

但是它会出现问题与if语句一起使用。对于可能出错的任何想法吗? :)

点赞
用户1190388
用户1190388

在 Lua 中,if 语句的语法如下:

if cond then
    statement
elseif cond then
    statement
else
    if cond then
        statement
    else
        statement
    end
end

你缺少了 then 子句。

2015-09-22 09:50:10