Hi all.
The following code doesn't work -- players don't get drawn.
What am I doing wrong?
Thanks in advance.
Alex
players = {} function make_player(col) local p = {} p.x = 0 p.y = 0 p.color = col return p end function draw_player(p) rectfill(p.x-2,p.y-2,p.x+2,p.y+2,p.color) end function _init() players.home = make_player(1) players.visitor = make_player(8) end function _draw() cls() foreach(players, function(p) draw_player(p)) end |
foreach() and all() and count() only operate on sequential integer indexes starting from 1.
so
> a = {name="bob","foo","bar","baz", x=1, y=5,[4]="wizzle",[6]="nope"} > foreach(a,print) foo bar bar wizzle |
Do you have any sample code -- or some docs -- for pairs? I'm curious as to usage.
[Please log in to post a comment]