ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 09 May 2012 04:43 PM |
I have a function:
function plotGrid(centerP, mPos, grid, cellSize) local p = mPos - centerP local cellX = math.floor((p.x/cellSize) + 0.5) local cellZ = math.floor((p.y/cellSize) + 0.5) local cellPos = centerP + Vector2.new(cellX * cellSize, cellZ * cellSize)
print("Origonal position was: ".. centerP.x, centerP.y) print("Cell position is: ".. cellPos.x, cellPos.y)
for i = 1, #grid do if grid[i].Position == Vector3.new(cellPos.x + centerP.x, 1.2, cellPos.y + centerP.y) then grid[i].BrickColor = BrickColor.new("Bright green") elseif grid[i].Name ~= "Center" then grid[i].BrickColor = BrickColor.new("Pastel Blue") else grid[i].BrickColor = BrickColor.new("Bright red") end end end
It reads a preexisting grid with cells the size of number cellSize, centered at centerP. It turns the cell that contains the Vector2 point mPos green, if it exists. I KNOW the cell exists, and yet it does not find it. Why? |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 09 May 2012 04:44 PM |
| What do you mean it does not find it? |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 09 May 2012 04:46 PM |
| I mean, the cell exists, it's position is what the if statement looks for (I know because I had it print the position), and it doesn't turn green. |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 09 May 2012 05:15 PM |
I made some mods... and nothing I tried worked. This was my last try:
function plotGrid(centerP, mPos, grid, cellSize, rows, columns) local p = mPos - centerP local cellX = math.floor((p.x/cellSize) + 0.5) local cellZ = math.floor((p.y/cellSize) + 0.5) local cellPos = centerP + Vector2.new(cellX * cellSize, cellZ * cellSize)
print("Origonal position was: ".. centerP.x, centerP.y) print("Cell position is: ".. cellPos.x, cellPos.y)
if rows/2 == math.ceil(rows/2) then rowOS = cellSize/2 else rowOS = 0 end
if columns/2 == math.ceil(columns/2) then colOS = cellSize/2 else colOS = 0 end --print("Searches for: ".. (cellPos.x * cellSize) + centerP.x + rowOS, (cellPos.y * cellSize) + centerP.y + colOS) for i = 1, #grid do if grid[i].Position == Vector3.new(cellPos.x, 1.2, cellPos.y) then grid[i].BrickColor = BrickColor.new("Bright green") elseif grid[i].Name ~= "Center" then grid[i].BrickColor = BrickColor.new("Pastel Blue") else grid[i].BrickColor = BrickColor.new("Bright red") end end end
Always prints that the cellPos is 2.5, 5... Not even close by my calculations. I radically changed value 'p' up at the top. No change in cellPos. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 09 May 2012 05:44 PM |
| I don't see much logic behind your code. Could you explain to me what you are trying to use this for? |
|
|
| Report Abuse |
|
|
ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 11 May 2012 01:42 PM |
| I got it to work. It's a little convoluted, but the short version is that it gets the cell the point 'p' is in and makes it green. |
|
|
| Report Abuse |
|
|