I am making a holo script, but I ran into a snag when I came across the Command Style configuration.
It prints out the CommandStyle, but everything else prints out as a blank.
local CmdStyles = { ["Plain"] = {CmdSep = " ", CmpKey = "c", RKey = "r", EKey = "e", AKey = "cmpadmin"}, ["Kohl"] = {CmdSep = " ", CmpKey = ":c", RKey = "r", EKey = ":e", AKey = ":cmpadmin"}, ["Person299"] = {CmdSep = "/", CmpKey = "c", RKey = "r", EKey = "e/", AKey = "cmpadmin"}, ["Sinfully"] = {CmdSep = " ", CmpKey = "/c", RKey = "r", EKey = "/e", AKey = "/cmpadmin"}, ["RCL"] = {CmdSep = " ", CmpKey = "!c", RKey = "r", EKey = "!e", AKey = "!cmpadmin"}, } local CommandStyle = "Plain" local CommandSeperator = "" local ComputerKey = "" local RunKey = "" local EndKey = "" local AdminKey = "" for i = 1, #CmdStyles do if CommandStyle == CmdStyles[i] then CommandSeperator = CmdStyles[i].CmdSep ComputerKey = CmdStyles[i].CmpKey RunKey = CmdStyles[i].RKey EndKey = CmdStyles[i].EKey AdminKey = CmdStyles[i].AKey end end print(CommandStyle, CommandSeperator, ComputerKey, RunKey, EndKey, AdminKey) -- Debugging
That's because they are blank (see you definitions on lines 13 - 17)
The if
isn't ever firing. You can check this yourself with code like this:
... for i = 1, #CmdStyles do if CommandStyle == CmdStyles[i] then print("It worked at",i) CommandSeperator = CmdStyles[i].CmdSep ... end end
At seeing that it doesn't work, you could check what each comparison is seeing:
for i = 1, #CmdStyles do print(CommandStyle, "==", CmdStyles[i]) if CommandStyle == CmdStyles[i] then CommandSeperator = CmdStyles[i].CmdSep ... end end
And you'll see absolutely nothing -- this means the for
loop isn't working.
Let's print
out #CmdStyles
, and we'll get 0
.
The way you have defined CmdStyles
, it has indices like "Plain"
which are not numbers and don't contribute to table length (#
). That also means that a for
loop using i = 1, #CmdStyles
won't work, since no numbers are keys in CmdStyles
You should use a pairs
loop to fix this:
for i, c in pairs(CmdStyles) do if CommandStyle == c then CommandSeperator = c.CmdSep ... end end
However, you'll see that that doesn't work (and a print
will verify that the if
is never happening).
We can compare the values in each step of the for loop like before, and get
Plain == table: 0x9ce870 Plain == table: 0x9cd380 Plain == table: 0x9cf5d0 Plain == table: 0x9cd430 Plain == table: 0x9cec90
We should actually be comparing to i, the index:
if CommandStyle == i then
Alternatively, since we're just looking for a particular value, you don't need the loop at all:
local style = CmdStyles[ CommandStyle ] local CommandSeperator = style.CmdSep local ComputerKey = style.CmpKey ...