Question about the widget ScrollView

Hi everyone,

I have a question about ScrollView, I insert some rect into a Scrollview like:

draw_list[data_set_index][j]=display.newRect(50,50,3,3,1)

scrollView:insert( draw_list[data_set_index][j] ) 

Now I want to get the insert rect, and move them from x position to x+50 position.

I can’t use draw_list[data_set_index][j].x=draw_list[data_set_index][j].x+50. Because after I insert this rect into the scrollview, draw_list[data_set_index][j] return me nil.

Can anyone help me?

Thank you very much

what is the “j” variable and how are you setting it?   Is it still in scope when you try to access it later, or has it been reset to nil or 0 or something else maybe after a for loop?

Keep in mind that if you do this:

local i = 100

print(i)

for i = 1, 5 do

     print(i)

end

print(i)

you will get

100

1

2

3

4

5

100

The i in the for loop is local to that loop only and doesn’t impact it.  So if your j variable is a loop index, it’s likely  not what you think it is later.

Thank you for reply, I will check my code, then tell you the details,

Thx a lot

Thank you Rob Miracle, I change j to a global variable, the problem is fixed.

what is the “j” variable and how are you setting it?   Is it still in scope when you try to access it later, or has it been reset to nil or 0 or something else maybe after a for loop?

Keep in mind that if you do this:

local i = 100

print(i)

for i = 1, 5 do

     print(i)

end

print(i)

you will get

100

1

2

3

4

5

100

The i in the for loop is local to that loop only and doesn’t impact it.  So if your j variable is a loop index, it’s likely  not what you think it is later.

Thank you for reply, I will check my code, then tell you the details,

Thx a lot

Thank you Rob Miracle, I change j to a global variable, the problem is fixed.