• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Lua tables - Hyphens not able to be used in table variables

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
Had something similar to this (going from memory.. since I fixed the issue...)
Code:
local config = {
    [1111] = {break = 50, lesser_value = 0,
        normal_item_table = {
            [1] = {item_id = 1111, count = 1},
            [2] = {item_id = 1111, count = 1}
        },
        semi-rare_item_table = {
            [1] = {item_id = 1111, count = 1},
            [2] = {item_id = 1111, count = 1}
        },
        rare_item_table = {
            [1] = {item_id = 1111, count = 1},
            [2] = {item_id = 1111, count = 1}
        }
   
    },
    [2222] = {break = 50, lesser_value = 0,
        normal_item_table = {
            [1] = {item_id = 1111, count = 1},
            [2] = {item_id = 1111, count = 1}
        },
        semi-rare_item_table = {
            [1] = {item_id = 1111, count = 1},
            [2] = {item_id = 1111, count = 1}
        },
        rare_item_table = {
            [1] = {item_id = 1111, count = 1},
            [2] = {item_id = 1111, count = 1}
        }
   
    }
}
The above code gives me this error.. (or something very similar)
Code:
[Error - LuaInterface::loadFile] data/actions/scripts/script.lua:7: '}' expected(to close '{' at line 2) near '=' data/actions/scripts/script.lua

For some reason hyphens (-----), cannot be used in the table variables.
Does anyone know why they can't be used?

To fix the issue I simply changed it like below, but it was just a little annoying spending 15 minutes scouring my table trying to find the issue. lol
Code:
semi-rare_item_table -- old
semi_rare_item_table -- new
["semi-rare_item_table"] -- alternate
^^ (then use a string in my code.. a little too annoying for such a small issue though.)

Anyways,
Posting this is case anyone knows the reason why hyphens can't be used, and in case someone else has the same issue but can't solve it. :oops:
 
The hyphens is a magic character in Lua.

You can escape that with a percent symbol infront of the hyphen.
Code:
%-
I tried to use the escape before however I ended up with the same error.
Am I using the escape incorrectly?
Code:
semi%-rare_item_table = {
    [1] = {item_id = 1111, count = 1},
    [2] = {item_id = 1111, count = 1}
},
 
Back
Top