1

I'm trying to create an if-else statement in Lua script. But I can't really get it to work :( This is what I have.

First I have a randomizer that can choose between some plans

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

Then if the priceplan is equal to 'Fast' I want to run another randomizer

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

But it is with the if statement that it seems so crash. Any ideas on what could possible be wrong :)?

1
  • 2
    You should have got this error message: 'then' expected near 'local', which is quite clear. Commented Sep 22, 2015 at 11:45

1 Answer 1

2

In Lua, the syntax of an if statement is as follows:

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

You're missing the then clause.

Sign up to request clarification or add additional context in comments.

1 Comment

I went to the bathroom and though. I maybe forgot the then clause... and hurry back to remove my question :) But yes sir it worked right away. thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.