kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 28 Jul 2012 05:44 PM |
This HUGE function can have many tags. HUGE, magnificent, genius, kool, and can you say, not working?
Here it is, can you fix it?
function closerTo(number, pointa, pointb) local dista = math.abs(number - pointa) local distb = math.abs(number - pointb) if distb < dista then return distb elseif dista == distb then return dista else return dista end end
function Round(Num, Increment) Interger = Increment --Too lazy to replace increment with every 'interger'. if Increment == nil then Increment = 1 end --Assume one if not defined. local Middle = Increment/2 if Num >= Middle then return math.ceil(Num/Interger)*Interger else return math.floor(Num/Interger)*Interger end end
function Check(mouseP, sizeX, sizeZ) targetCell, targetCellMaterial = Workspace.Terrain:GetCell(Round(mouseP.x, 4)/4, 2 ,Round(mouseP.z, 4)/4) cellMaterials = {targetCellMaterial} if size == 1 or size == nil then if targetCell and targetCellMaterial == 1 then return true else return false end else local Znum, Xnum local Num, Num2 = closerTo(mouseP.x, math.floor(Round(mouseP.x-.1, 4)), math.ceil(Round(mouseP.x+.1))), closerTo(mouseP.x, math.floor(Round(mouseP.z-.1, 4)), math.ceil(Round(mouseP.z+.1))) if Num == math.floor(Round(mouseP.x-.1, 4)) then Xnum = -1 else Xnum = 1 end if Num2 == math.floor(Round(mouseP.x-.1, 4)) then Xnum = -1 else Xnum = 1 end for x = 1*Xnum, sizeX*Xnum, Xnum do for z = 1*Znum, sizeZ*Znum, Znum do local cell, cellMat = Workspace.Terrain:GetCell((Round(mouseP.x, 4)/4)*x, 2, (Round(mouseP.z, 4)/4)*z) table.insert(cellMaterials, cellMat) end end for i,CellMaterial in pairs(cellMaterials) do if not CellMaterial == 1 then return false end end return true end end
Eeek. Too big. |
|
|
| Report Abuse |
|
|
Dr01d3k4
|
  |
| Joined: 11 Oct 2007 |
| Total Posts: 17916 |
|
|
| 28 Jul 2012 05:46 PM |
| That's not that long, and you didn't give any information about what the error is. |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2012 05:46 PM |
| Indeed, what's the output? |
|
|
| Report Abuse |
|
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 28 Jul 2012 05:56 PM |
There is no output, it keeps returning false.
And I updated the closerTo function.
function closerTo(number, pointa, pointb) local dista = math.abs(number - pointa) local distb = math.abs(number - pointb) if distb < dista then return pointb elseif dista == distb then return pointa else return pointa end end |
|
|
| Report Abuse |
|
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 28 Jul 2012 06:08 PM |
This is the only part, 'yall' should worry about.
function Check(mouseP, sizeX, sizeZ) targetCell, targetCellMaterial = Workspace.Terrain:GetCell(Round(mouseP.x, 4)/4, 2 ,Round(mouseP.z, 4)/4) cellMaterials = {targetCellMaterial} local Znum, Xnum local Num, Num2 = closerTo(mouseP.x, math.floor(Round(mouseP.x-.1, 4)), math.ceil(Round(mouseP.x+.1))), closerTo(mouseP.x, math.floor(Round(mouseP.z-.1, 4)), math.ceil(Round(mouseP.z+.1))) if Num == math.floor(Round(mouseP.x-.1, 4)) then Xnum = -1 else Xnum = 1 end if Num2 == math.floor(Round(mouseP.x-.1, 4)) then Xnum = -1 else Xnum = 1 end for x = 1*Xnum, sizeX*Xnum, Xnum do for z = 1*Znum, sizeZ*Znum, Znum do local cell, cellMat = Workspace.Terrain:GetCell((Round(mouseP.x, 4)/4)*x, 2, (Round(mouseP.z, 4)/4)*z) table.insert(cellMaterials, cellMat) end end for i,CellMaterial in pairs(cellMaterials) do if not CellMaterial == 1 then return false end end return true end |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2012 06:10 PM |
| Quite the script you've got there. I'm new to scripting, and I'm guessing this has to do with some form of terrain editor? |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2012 06:11 PM |
| I'm asking this due to the highlight function, grid requirements, workspace and terrain coding in the script itself. |
|
|
| Report Abuse |
|
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 28 Jul 2012 06:15 PM |
| Yes, I'm currently de-bugging it actaully. Some amount of nil variable and such. 'Yes' was to your question Phunguy. |
|
|
| Report Abuse |
|
|
|
| 28 Jul 2012 06:19 PM |
| For one, the GetCell doesn't return the cell and its material. It returns (in this order): the material, shape, and orientation. |
|
|
| Report Abuse |
|
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
| |
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 28 Jul 2012 06:26 PM |
Alright, but now it only returns true.
function Check(mouseP, sizeX, sizeZ) targetCellMaterial = Workspace.Terrain:GetCell(Round(mouseP.x, 4)/4, 2 ,Round(mouseP.z, 4)/4) cellMaterials = {targetCellMaterial} if sizeX == 1 and sizeZ == 1 then if targetCell and targetCellMaterial == 1 then return true else return false end else local Znum, Xnum local Num, Num2 = closerTo(mouseP.x, math.floor(Round(mouseP.x-.1, 4)), math.ceil(Round(mouseP.z+.1))), closerTo(mouseP.z, math.floor(Round(mouseP.z-.1, 4)), math.ceil(Round(mouseP.z+.1))) if Num == math.floor(Round(mouseP.x-.1, 4)) then Xnum = -1 else Xnum = 1 end if Num2 == math.floor(Round(mouseP.z-.1, 4)) then Znum = -1 else Znum = 1 end for x = 1*Xnum, sizeX*Xnum, Xnum do for z = 1*Znum, sizeZ*Znum, Znum do local cellMat = Workspace.Terrain:GetCell((Round(mouseP.x, 4)/4)*x, 2, (Round(mouseP.z, 4)/4)*z) table.insert(cellMaterials, cellMat) end end for i,CellMaterial in pairs(cellMaterials) do if not CellMaterial == 1 then return false end end return true end end |
|
|
| Report Abuse |
|
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 28 Jul 2012 06:46 PM |
| Alright, I found the problem. How do you compare Enums? |
|
|
| Report Abuse |
|
|
| |
|