1,441 questions
0
votes
0
answers
141
views
How do I create larger structs using tables in lua? (in the pico-8 game engine)
I am making a card game and im now revamping how individual card information is stored.
a single card would have the following values:
x, y, suit, number, state
this is to be stored in a deck array ...
1
vote
1
answer
91
views
How to iterate through the non-numeric indices of a table without using the pairs or next functions? [closed]
So I have the following table:
local table_arr = {
a = 3,
b = 42,
c = 10
}
And my for loop:
for x=1, #table_arr do
local key, value = table_arr[x], arr[ table_arr[x] ]
print(key) -...
2
votes
3
answers
104
views
Why do these Lua array initialization constructs have differing semantics?
As I understand Lua, an array is just a table where the keys start at 1 and increment sequentially. However, there are features within Lua to manipulate arrays in the traditional sense (e.g. ipairs, ...
1
vote
1
answer
63
views
Lua returns only empty tables
I have a code:
function subsets(t)
local res={}
local res_t={}
function subs(i)
if i>#t then
res[#res+1]=res_t
return
end
res_t[#res_t+1]...
0
votes
2
answers
81
views
Change brick color repeatedly
I'm trying to make a dance floor that lights up and changes colors periodically. So far I've gotten the game to load and pick a random color from the array upon loading, but I can't make the tiles ...
0
votes
0
answers
92
views
Lua table index changes its values without assigning any to them
Lua table (ref) index changes its values without assigning any to them.
Why does ref table change its values after assigning it to tab[c] or using string.match()? The actual behavior is that the ref ...
-1
votes
1
answer
77
views
How to block functions from being overwritten?
I program in Lua and I need some help:
I have file1.lua and file2.lua
In file1.lua:
loadstring('print("Hello World!")')
in file2.lua:
_loadstring = loadstring
function loadstring(code)
...
1
vote
0
answers
29
views
Is it possible to identify a table from a string variable? [duplicate]
I have this function that takes a string (s) and returns a table depending on what I entered.
function String2Faction(s)
if s == "Nomads" then
return Faction_Nomads
elseif s =...
3
votes
1
answer
75
views
table.insert not replacing the first nil position in the table
I started learning Lua recently, as far as I can tell, when I don't specify the index, the function table.insert tries to put the value in the first nil in the table.
Why then is it that in table t ...
0
votes
1
answer
457
views
Attempt to call missing method of table
I'm trying to make my first Roblox studio game and I ran into this problem:
attempt to call missing method 'UpdateCharacter' of table
attempt to call missing method 'Equip' of table
Any function ...
1
vote
1
answer
93
views
Lua equivalent for null conditional operator? [duplicate]
In lua, if we try to index a series of nested table (any of which can be nil), we might write code like this:
-- try to get a.b.c
local ret
if a then
local b = a.b
if b then
ret = b.c
...
1
vote
1
answer
52
views
Any way to combine two tables in lua?
Like I got two tables:
{["a"] = "aaa"} and {["b"] = "bbb"}
And make it into one table: {["a"] = "aaa", ["b"] = "bbb"}
I ...
2
votes
1
answer
30
views
Value not changing between tables
Here's code for a timer:
local copyTable = require("Helpers.copyTable")
local timer = {}
timer.max = 0
timer.time = 0
function timer:add(dt)
timer.time = timer.time + dt
end
function ...
3
votes
2
answers
134
views
Repacking or printing unpacked Lua tables
Why does the table.unpack() function print the unpacked table only if there is nothing following the function?
> print(table.unpack({1,2,3}))
1 2 3
> print(table.unpack({1,2,3}),&...
1
vote
1
answer
77
views
Getting the key a value was assigned to in a table in lua
So I'm trying to make a table of all the creatures in a game, each creature consisting of a table with their stats. I used the creature's name as the key in the first table, but now I need to get that ...