Log In  

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

P#53615 2018-06-16 17:38 ( Edited 2018-06-17 10:52)

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!

P#53621 2018-06-17 02:35 ( Edited 2018-06-17 06:35)

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

P#53626 2018-06-17 06:52 ( Edited 2018-06-17 10:52)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 14:29:39 | 0.006s | Q:12