generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Grid reader

Previous Thread :: Next Thread 
ZizZazZuz is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image