Hi devs,
I'm tryin' to code a Magical Drop demake, and currently i'm doing the pull mechanic, but in the for loop where i get all the drops with the same color i can't set them to blank (value = 5, the blank sprite slot). It's like it doesn't read that line at all :/
Here is the snippet, in case someone comes up with something.
function drps_by_v(c,v) local ds={} for d in all(c) do if d==v then add(ds,d); d=5; -- here i set them to blank elseif d~=5 and d~=v then return ds; end end return ds; end |
where "c" is for column of the player board and "v" the first drop value of the column (to get all consecutive same drops).
Lots of thank in advance! :D



you cannot change the ‘d’ value - lua gives you a value, not a reference to a table element.
Options:
- use an indexed iterator
for i=1,#c do local d=c[i] if d==v then c[i]=5 ... |
- make your elements tables
for _,d in pairs(c) do if d==v then d.spr=5 ... |
note: you should stop using ; to terminate statements, that’s useless!



Wow thx! That was easy :_D. It seems that i'm still not very accustomed to some features of Lua (since i usually code on Java and C#), i'll apply it immediatly, thx again! :D
[Please log in to post a comment]