Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errors when including hyphens in table variables

Tags:

lua

I recently bought MaterialBoard from ScriptFodder. I am editing the groups list so it will show the capitalized & un-hyphened group names so instead of head-admin it would look like "Head Admin". Everything has worked so far but once it started using hyphens in the variable name, it concluded errors:

[ERROR] addons/materialboard/lua/matboard_config.lua:76: '}' expected (to close '{' at line 73) near '='
    1. unknown - addons/materialboard/lua/matboard_config.lua:0

how do I make it so I can include hyphens in a table variable name like this?

co-owner   = "Co-Owner",
like image 211
JacobRocks12 Avatar asked Dec 19 '22 20:12

JacobRocks12


1 Answers

local t = {co-owner = "Co-Owner"}

is not valid because - cannot be used in an identifier. Instead, use the more general syntax:

local t = {["co-owner"] = "Co-Owner"}
print(t["co-owner"])
like image 114
Yu Hao Avatar answered Jan 10 '23 18:01

Yu Hao