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
0
votes
3 answers

A table does not get deleted on scene change, CoronaSDK Storyboard

Basically, I have a table that has images that move horizontally, when I change scenes it stays there, even though I didn't call for it.. As in, on there is no code for it in offlinemode.lua.. I'm thinking that for some reason it's a global…
0
votes
1 answer

Can I put a lua_table in another table to build a multi-dimensional array via C++?

for my game im trying to accomplish the following array structure by C++ because the data come from an external source and should be available in a lua_script. The array structure should look like this: (The data are in a map, the map contains the…
Steini
  • 2,753
  • 15
  • 24
0
votes
1 answer

Lua sorting tables

I know nothing about Lua, but I was able to modify a script I wanted to. I'm having troubles sorting a table though. I've found table utils (convert table to string), here's my table: {{line="(Golden Aura) Challenging An owl would be either very…
0
votes
2 answers

Parsing large .txt files in Lua without tables

I'm reasonably new to Lua although I have used other languages which are similar. So far I've spent 8 hours to no avail trying to parse a large text file. The file in question looks something like this: (but thousands of lines long) A|KLAX|LOS…
user2609216
  • 35
  • 1
  • 5
0
votes
2 answers

bad argument #1 to 'pairs' (table expected, got nil)

So I'm trying to program a space invaders like game in lua using löve2d, the first wave of enemies runs smoothly but once i try adding another wave to the levelctrl table i get this error: bad argument #1 to 'pairs' (table expected, got nil) on line…
Jesus M Lopez F
  • 11
  • 1
  • 1
  • 5
0
votes
1 answer

Clearing a table in corona

I'm having problems with clearing the data in a LUA table. I use the Scene plugin and as soon as the player advances to the next scene, then I'd like to reset the data in a table. I use this function to create the game elements: local function…
jumbee
  • 95
  • 1
  • 7
0
votes
2 answers

Removing entry from table

Can't remove an entry from table. here's my code dropItem = dropList[ math.random( #dropList ) ] dropSomething[brick.index] = crackSheet:grabSprite(dropItem, true) dropSomething[brick.index].x = brick.x dropSomething[brick.index].y =…
Bnhjhvbq7
  • 169
  • 3
  • 13
0
votes
2 answers

Attempt to index global 'LM' (a nil value)

I am working on a some code in Lua and I keep getting this error although it is defined. It is saying that 'LM' is a nil value when it's clearly not as LM = {} is the first thing I have in my code. I am using that table for functions. LM =…
Ripmax
  • 21
  • 2
0
votes
3 answers

dynamic tables or arrays

I have a function that is meant to dynamically change the size of a 3D Array or table but it keeps breaking saying that it return value nil because it is out of bounds. Here is the code for it: function resize() temp = { } for h=1,…
5tar-Kaster
  • 910
  • 2
  • 12
  • 30
0
votes
2 answers

Balancing equally-sized arrays

I don't know it the correct name is "balance". Well I have an array of 2n positive integer elements and I want to split into two n elements array, with the minimum difference between their average. For example: values: {4, 4, 7, 8, 10, 15} (some…
ranieri
  • 2,030
  • 2
  • 21
  • 39
0
votes
2 answers

Looping through tables in a table in Lua

I've hit a complete dead end with this. This is probably going to be something incredibly basic and it will most likely result in me smashing my head into a wall for having a major brain fart. My question is basically, how do you loop though tables…
0
votes
3 answers

Is there a PHP foreach equivelent in Lua?

I have gotten used to programming in PHP with the foreach statement: Is there an equivalent to this in Lua? Thanks! Relevant sections: function renderobjects() o1 = object:new{x = 30, y = 30, roomx = 0, roomy = 0, symbol = "t", name = "Tree"} …
William
  • 570
  • 3
  • 17
0
votes
2 answers

Lua: Print value from nested table

I feel like this is a really silly question... t = { a = {x,y}, b = {z}, } How do I print the first value of the key 'a'? ("x") Neither print(t["a"][1]) nor print(t.a[1]) does it, so how would I go about? What's the difference between '[]' and…
Easypeasy
  • 150
  • 2
  • 11
0
votes
2 answers

How to call a table using a command line argument in lua

I am trying to make a program that can run a program with certain conditions. Basically, I am using ComputerCraft with Minecraft and a turtle to retrieve items then go back to where it started. I stored all the coordinates inside tables individually…
dyl421421
  • 11
  • 3
0
votes
1 answer

Search for a key in lua which contains a certain string

I have multiple lua files which contain information I would like to extract via Python. To use Lua inside Python I'm using lunatic-python, but thats not a requirement - if you have other approaches that would also be fine. The lua files look like…
soerface
  • 6,417
  • 6
  • 29
  • 50