Is there a way to make this loop?

if string.find(level.tileArray[y][x], "p") then if level.tileArray[y][x] == "p1" then x1[1] = rect[total].x y1[1] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p2" then x1[2] = rect[total].x y1[2] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p3" then x1[3] = rect[total].x y1[3] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p4" then x1[4] = rect[total].x y1[4] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p5" then x1[5] = rect[total].x y1[5] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p6" then x1[6] = rect[total].x y1[6] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p7" then x1[7] = rect[total].x y1[7] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p8" then x1[8] = rect[total].x y1[8] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p9" then x1[9] = rect[total].x y1[9] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p10" then x1[10] = rect[total].x y1[10] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p11" then x1[11] = rect[total].x y1[11] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p12" then x1[12] = rect[total].x y1[12] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p13" then x1[13] = rect[total].x y1[13] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p14" then x1[14] = rect[total].x y1[14] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p15" then x1[15] = rect[total].x y1[15] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p16" then x1[16] = rect[total].x y1[16] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p17" then x1[17] = rect[total].x y1[17] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p18" then x1[18] = rect[total].x y1[18] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p19" then x1[19] = rect[total].x y1[19] = rect[total].y rect[total].isRoad = true elseif level.tileArray[y][x] == "p20" then x1[20] = rect[total].x y1[20] = rect[total].y rect[total].isRoad = true end

Not sure what you mean? If you mean is there a way to do this in 2-3 lines, then yes, there is :wink:

if string.find(level.tileArray[y][x], "p") then local i = 1 while( i \< 21 ) do if( level.tileArray[y][x] == ("p"..i) ) then x1[i] = rect[total].x y1[i] = rect[total].y rect[total].isRoad = true i = 999 end i = i + 1 end end

Thank you very much! That is exactly what I was looking for! :slight_smile:

Not sure what you mean? If you mean is there a way to do this in 2-3 lines, then yes, there is :wink:

if string.find(level.tileArray[y][x], "p") then local i = 1 while( i \< 21 ) do if( level.tileArray[y][x] == ("p"..i) ) then x1[i] = rect[total].x y1[i] = rect[total].y rect[total].isRoad = true i = 999 end i = i + 1 end end

Thank you very much! That is exactly what I was looking for! :slight_smile: