grid problem to acces a value of a cell

Good evening everyone,

I have a problem to compare the scale of a grid to a value. I Would like that if the size of a very special cell is greater than 1.5 then I deploy a gray rectangle.

The problem is that it does not recognize the progression of a cell of the grid via the transition.scaleTo … What should I write for this to be interpreted correctly?

thank you for testing and for your help :slight_smile:

 

display.setStatusBar( display.HiddenStatusBar ) grid = {} local colonnes = 10 local lignes = 15 local rectx = 30 local recty = 30 local espacement = 2 local ecartgauche =10 local ecarthaut = 50 for i = 1, lignes do     grid[i] = {};     for k = 1, colonnes do         grid[i][k] = display.newCircle(100,100,50,50)         grid[i][k].yScale=0.2         grid[i][k].xScale=0.2         grid[i][k].alpha = 1         grid[i][k].x = (k - 1) \* (rectx + espacement) + ecartgauche         grid[i][k].y = (i - 1) \* (recty + espacement) + ecarthaut local tm = math.random(1500, 5500) transition.scaleBy(grid[i][k], {yScale=2, xScale=2,  time=tm, delay=tm} )     end end --spawn a rectangle when the scale is upper than... local function comparesscale() print( grid[4][5].yScale ) if grid[4][5].yScale \>= 0.3   then local rect=display.newRect(100,100,100,100)   rect:setFillColor( 0.5 ) end end comparesscale()

Nobody ?

You’re only running the comparesscale function once. When it runs, none of the objects will be above 0.3 in scale yet.

If you want the comparesscale function to run every frame:

[lua]

Runtime:addEventListener(“enterFrame”, comparesscale)

[/lua]

You might want to use a flag to determine whether an object has already passed your threshold, so you don’t generate thousands of rectangles:

[lua]

grid[i][k].spawned = false  – put this when creating the object

if grid[i][k].spawned == false and grid[i][k].yScale >= 0.3 then

  grid[i][k].spawned = true

end

[/lua]

You also don’t seem to be adding any of these objects to a display group which is going to give you memory leaks.

Nice thanks, and how to identify the value of [row][col] who is greater than 0.3 ?

Just loop through them like you did when you created them.

I don ´t understand what you mean…in case in i work with a random.math i dońt Know where the cell are created be cause the delay of spawn is random. I would like to know the value of the grid to attach an action of my character dépending of this position…

Nobody ?

You’re only running the comparesscale function once. When it runs, none of the objects will be above 0.3 in scale yet.

If you want the comparesscale function to run every frame:

[lua]

Runtime:addEventListener(“enterFrame”, comparesscale)

[/lua]

You might want to use a flag to determine whether an object has already passed your threshold, so you don’t generate thousands of rectangles:

[lua]

grid[i][k].spawned = false  – put this when creating the object

if grid[i][k].spawned == false and grid[i][k].yScale >= 0.3 then

  grid[i][k].spawned = true

end

[/lua]

You also don’t seem to be adding any of these objects to a display group which is going to give you memory leaks.

Nice thanks, and how to identify the value of [row][col] who is greater than 0.3 ?

Just loop through them like you did when you created them.

I don ´t understand what you mean…in case in i work with a random.math i dońt Know where the cell are created be cause the delay of spawn is random. I would like to know the value of the grid to attach an action of my character dépending of this position…