[Resolved] For loop

Hello,
I was playing around with function and to see if I could use my function in a for-loop. But I dont understand why my code not is working. The program is drawing the first line. But then it stops.

//Magnus

[code]
display.setStatusBar(display.HiddenStatusBar)

local _H=display.contentHeight;
local _W=display.contentWidth;
local function draw_line(x1,y1,x2,y2,w)
draw_line=display.newLine(x1,y1,x2,y2);
draw_line.width=w;
end
local i;
for i = 10, 100, 5 do
draw_line(0,i,_W,_H,3);
end
[/code] [import]uid: 146882 topic_id: 26300 reply_id: 326300[/import]

thats because your simply replacing the same object, rather than spawning.

this should work:

[code]
display.setStatusBar(display.HiddenStatusBar)

local _H=display.contentHeight;
local _W=display.contentWidth;

local function draw_line(x1,y1,x2,y2,w)
local draw_line=display.newLine(x1,y1,x2,y2);
draw_line.width=w;

return draw_line;
end

for i = 10, 100, 5 do
local line = draw_line(0,i,_W,_H,3);
end
[/code] [import]uid: 84637 topic_id: 26300 reply_id: 106585[/import]

Now I understand. Thanks. [import]uid: 146882 topic_id: 26300 reply_id: 106605[/import]