Hi everyone,
I would like to call functions within a table from within a for loop. The type of loop I want to use is as follows;
for x=#enemy,1,-1 do enemy.restoreenemybg[x]() end |
No matter what combination I try, I just can't get it to work.
FYI - The reason I'm using this type of for loop is because I need to loop in reverse. The following version doesn't allow this.
for e in all(enemy) |
I would really appreciate any help on this.
Many thanks,
I think you just got the [x] bit backwards. Try:
enemy[x].restoreenemybg() |
Tried that but, unfortunately didn't work. I forgot to mention that the function requires an ID (i.e Self)
restoreenemybg=function(self) restorespritebackground(self.xpos,self.ypos,self.bgaddr) end, |
The error I'm getting is;
Attempt to Index Local 'Self' (A Nil value)
Found it! The notation should be as follows;
enemy[x].restoreenemybg(enemy[x]) |
Now the loop is working fine. Thanks for helping though.
[Please log in to post a comment]