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 where card info can be accessed with,
deck[i].suit
yes, yes i can find the suit and number based on its index but no
now i could just individually type up the info for each card but im lazy so i made a init_deck function, that gets called once during...initialization.
deck={}
// lua starts loops with one
function init_deck(deck)
for s=1,4 do // iterate through the 4 suits
for n=1,13 do // iterate from ace to king
add(deck,{x=0,y=0,suit=s,number=n,state=1})
end
end
end
function init()
init_deck(deck)
end
function draw()
print(deck[2].number) // should print 2 // output is 13
print(deck[2].suit) // should print 1 // output is 4
print(deck[2].state) // should print 1 // output is 1
end
ive also used table.insert where add is being called to the same effect(with the same parameters, also tried with an index parameter, didint work), for some reason the variables that are affected by the for loop are assigned the highest value in the loop.
I am quite confused, Im assuming its a pico-8 thing because the lua documentation includes these things. any support would be appreciated, i now realize i could have manually made every card in the time it took to type this but...
init()before anyprint(), maybe some old values are being printed here.addis missing a closing parenth. Is that in the original code, or a copy-paste mistake? It would help if you formatted your code so that it was readable._initand_draw, notinitanddraw. Is this another "recreation" error? Best to provide accurate code examples. IAC, the code works in regular Lua (withtable.insertreplacingadd; I don't think that PICO-8 includes the Lua Standard Library, though). This should work in PICO-8 (modulo_initvs.init); the problem is likely in code not shown. Possible that other code is modifying the globaldeck.//tokens do not introduce comments in Lua, nor in PICO-8, I believe. Please provide accurate code samples that reproduce the problem. minimal reproducible example