Questions tagged [lua-table]

This tag refers to the table type in Lua that implements associative arrays.

The table type implements associative arrays. An associative array is an array that can be indexed not only with numbers, but also with strings or any other value of the language, except nil. Moreover, tables have no fixed size; you can add as many elements as you want to a table dynamically.

Tables in Lua are neither values nor variables; they are objects.

Creating table

t = {5, 10, 15, apple="red", banana="yellow" }

Short note about keys

Lua stores all elements in tables generically as key-value pairs. Lua does not differentiate between arrays and dictionaries. All Lua tables are actually dictionaries.

Note that keys are references to objects so you must use the same reference to get the same key into the table.

Useful Link

1403 questions
-1
votes
1 answer

Can I make table from other table elements?

Am I able to make a separated table filled with elements from other tables in Lua? Like this: TableA = { a=1, b=2, c=3 } TableB = { John=4, Jane =5 } TableC = { x = "asd", y = "dsa", z = "sda" } TableAll = { TableA.a, TableB.John, TableC.x} It's a…
Zoltán Schmidt
  • 1,286
  • 2
  • 28
  • 48
-1
votes
2 answers

Table Empty when adding content

I'm having a huge problem when I've added content to a table (Lua), where all content in the table suddenly disappears. The table in question holds the data for a banlist (608 entries at present) and is placed within the table by using…
AStopher
  • 4,207
  • 11
  • 50
  • 75
-1
votes
2 answers

Corona - Adding a listener to a table/array or to items in a table

I'm trying to add a touch event to an image randomly picked from a table using the following code: easyGame2 = function() catTable = { 'catwhite', 'catblue', 'catred', 'catyellow', 'catgreen', 'catorange', 'catpink', 'catpurple'} randomCat =…
reoh
  • 282
  • 5
  • 12
-1
votes
2 answers

How can I use a string in a table?

I need to use a string value as a table, in order to restore points to a player when they reconnect to a game server. This string value is their profile ID, which never changes and I need to put data inside the string value (Kills, deaths, head…
AStopher
  • 4,207
  • 11
  • 50
  • 75
-1
votes
1 answer

Lua accessing table stored in external file

I have an external lua file that has a table stored in it that is formatted as follows: sgeT = { 2535047 = { { ["account"] = "TG-MCB110105", ["exec"] =…
amber4478
  • 6,433
  • 3
  • 20
  • 17
-1
votes
1 answer

lua: table index is nil

I don't know lua, though I'm decent with a few other languages, so I'm not entirely ignorant in regards to tables and such I found this code online and was trying to use it but it keeps spitting out a table index is nil error. I've been looking at a…
Rob
  • 7,980
  • 30
  • 75
  • 115
-2
votes
2 answers

Lua Sleep and Loop function problems

So my script currently stops on conditions if profit >= 0.1 then stop() end i want to implement this code into mine so after the target satified it will sleep for 30 secs and then restart my dobet function if found this function sleep() t0 =…
-2
votes
1 answer

How would I convert a string into a table?

I have been trying to convert a string into a table for example: local stringtable = "{{"user123","Banned for cheating"},{"user124","Banned for making alt accounts"}}" Code: local table = "{{"user123","Banned for cheating"},{"user124","Banned for…
Lavacat
  • 11
  • 4
-2
votes
2 answers

Can this lua code be written better?

Can the following code be refactored to be more concise or more clear? I have also attached a picture below to help illustrate what I have in mind. local playerAreaPos = { {x = playerPos.x, y = playerPos.y - 1, z = playerPos.z}, -- NORTH …
Jay
  • 41
  • 9
-2
votes
1 answer

used string.gsub to change white space to _ not working

even if i use gsub to change white space to _ the if statement still get error attempt to index a nil value i wonder whats the problem.i cant use pairs since that's the instruction my teacher gave. this is the code sorry in advance im a beginner.…
-2
votes
2 answers

"Cast" the address of a Lua table to a Lua table

Say I have the address of a table - how would I "cast" a table variable to it? I'm not concerned about "bad practice" or crashes because this is just an individual problem. I want to do something like lua_table tab = *(lua_table*)0xaddr ...but…
Lupe
  • 319
  • 1
  • 3
  • 16
-2
votes
1 answer

Formatting lua table for a parse $in query that is also a table

I am using corona (lua) with parse.com and I have hit a problem constructing an $in query using values from another table / array. My code is a little like this: local usersToFetch = {} table.insert( usersToFetch, "KnVvDiV2Cj") table.insert(…
user3781891
  • 135
  • 10
-2
votes
2 answers

How to compare a bunch of values with themselves

I have a list of indexes I need my users to input, and I need the code to check if any of them are repeated, so it would give an error (they cannot be repeat). if i only had two indexes it would be simple as : if indexa == indexb then error()…
Mojimi
  • 2,561
  • 9
  • 52
  • 116
-2
votes
1 answer

Access one field of a table that is in a table (nested) Lua

i have a table that looks like this: tbm = { -- facedir indexed (+1) { -- facedir = 0 { -- first line { X = -1, Y = 2, Z = 1 }, { X = 0, Y = 2, Z = 1 }, { X = 1, Y = 2, Z = 1…
FatBoi1942
  • 45
  • 5
-2
votes
1 answer

Lua dont allow table append

I already have a lua-table A={}, A.B={} under global variable. I have a function on the call of what creates lua table D1={}, D1.D2={}, but the porblem is this function places the table in global variable list. When i print all lua values, it…
Darshan Nair
  • 323
  • 1
  • 5
  • 11
1 2 3
93
94