Goto and Labels

  • Mdkar
    12th Feb 2015 Member 0 Permalink

     

     

    I was trying to make a small loop in code.   I can't seem to get goto and labels to work in Lua.  I also don't know if the rest of the code works properly.  Here's what I have:

     

    ::redo::

        local a = math.random(0,255)

        local b = math.random(0,255)

        local c = math.random(0,255)

        if ((a-b) or (b-c) or (c-a)) <= 15 or ((a-b) and (b-c) or (c-a))>=-15 then goto redo

  • FeynmanLogomaker
    12th Feb 2015 Member 0 Permalink

    That's because they were added in Lua 5.2 (I think), while TPT uses Lua 5.1.

    Try using this instead:

     

    do
    local a = math.random(0,255)
    local b = math.random(0,255)
    local c = math.random(0,255)
    until not( ((a-b) or (b-c) or (c-a)) <= 15 or ((a-b) and (b-c) or (c-a))>=-15 )

     

    EDIT: Or you could run it in my mod

    Edited once by FeynmanLogomaker. Last: 12th Feb 2015
  • Mdkar
    12th Feb 2015 Member 0 Permalink

    I am on mac, so I don't think I can use your mod (I use Jacb1's).  I still dont know where to place the "end" in the script you provided. Help? Please?

    Edited once by temporaryaccount. Last: 12th Feb 2015