• 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!

I need some LUA tables examples.

Hermes

dziwki kola gramy w lola
Joined
Nov 17, 2007
Messages
1,867
Reaction score
14
Location
Poland
Hi there!

5 minutes ago I realised, that I suck at advanced tables, so I have few questions to you, OTLanders!

1. How should look like ordinary table, which will work like:
Code:
local table = [object1, object2, object3]
local something = object2
if something == "one of items from table" then
doBroadcastMessage("Object matches to one of items from table.", MESSAGE_STATUS_CONSOLE_ORANGE)
elseif something == "is not one of the items in table" then
doBroadcastMessage("Sorry, object doesn't match any of items in table.", MESSAGE_STATUS_CONSOLE_ORANGE)
end
2. How I can add values to table after defining it?
For example:
Code:
local table = [1, 2, 3, 4, 5]
if something == something then
"add to table value 6"
"replace in table value 1 to 7"
end
3. I saw that someone was using function (to do something with tables :p) "isInArray". How this function exactly works? And what's it's general purpose and usage?

Thanks in advance, Hermes
 
1.
isInArray(array, value)

for example:
Code:
local someThing = {1, 2, 3, 4, 5}

if(isInArray(someThing, 3) == TRUE) then -- true

2.
local testTable = {1, 2, 3, 4, 5}

table.insert(testTable, 6)
testTable[1] = 7
 
Back
Top