I want:
buttons = {"off" {19,8,22,8}, "enter" {17,5,22,5}, "input" {5,5,17,5}}
So that I can use it like so:print(buttons["off"[1]]) --buttons["off"] is equal to buttons[1] right? result = 19Any help is appreciated!
Posted 19 October 2013 - 01:57 PM
buttons = {"off" {19,8,22,8}, "enter" {17,5,22,5}, "input" {5,5,17,5}}
So that I can use it like so:print(buttons["off"[1]]) --buttons["off"] is equal to buttons[1] right? result = 19Any help is appreciated!
Posted 19 October 2013 - 02:08 PM
buttons = {["off"] = {19,8,22,8}, ["enter"] = {17,5,22,5}, input = {5,5,17,5}}
Just don't forget [] if you put the name inside ""buttons = {["off"] = {19,8,22,8}, ["enter"] = {17,5,22,5}, input = {5,5,17,5}}
print(buttons["off"][1]) --buttons["off"] is equal to buttons[1] right?
result = 19
print("Result: " ..result)
Posted 19 October 2013 - 02:12 PM
buttons = {
["off"] = { -- make the brackets around the name of this new table. -- then assign values to the table
19,
8,
22,
8,
};
}; -- btw you can also do a table like this. (multiline)
print(buttons["off"][3]) -- the number here is the value in the "off" table.. (well you already know that)
local tbl = {
value1 = "VAL1";
["tbl2"] = {
value2 = "VAL2";
["tbl3"] = {
value3 = "VAL3";
["tbl4"] = {
value4 = "VAL4";
--- etc.....
};
};
};
};
print(tbl["tbl2"]["tbl3"]["tbl4"].value4)
Posted 19 October 2013 - 03:35 PM
if (sEvent == "mouse_click") then for i=1,3 do local atyes = w.coordCheck(p2,p3,buttons[i][1],buttons[i][2],buttons[i][3],buttons[i][4]) if (atyes == true) then functions[buttons[i]]() end endAlthough, at line 3 (in the example above) I receive "attempt to index? (a nil value)
Posted 19 October 2013 - 04:19 PM
buttons = {
off = {19,8,22,8},
enter = {17,5,22,5},
input = {5,5,17,5}
}
print(buttons.off[1]) --> 19or through a string:
print(buttons["off"][1]) --> 19
str = "off" print(buttons[str][1]) --> 19
str = "off" print(buttons.str[1]) --> errorBecause lua will actually look for buttons["str"], and not buttons[str].
for name, button in pairs(buttons) do print(name, button[1]) end
off 19 enter 17 input 5
Posted 19 October 2013 - 06:27 PM
Posted 19 October 2013 - 06:36 PM
Wing, on 19 October 2013 - 03:35 PM, said:
if (sEvent == "mouse_click") then for i=1,3 do local atyes = w.coordCheck(p2,p3,buttons[i][1],buttons[i][2],buttons[i][3],buttons[i][4]) if (atyes == true) then functions[buttons[i]]() end endAlthough, at line 3 (in the example above) I receive "attempt to index? (a nil value)
buttons = { {19,8,22,8}, {17,5,22,5}, {5,5,17,5} }
0 members, 2 guests, 0 anonymous users