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: HUGE Function

Previous Thread :: Next Thread 
kools is not online. 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 is not online. 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
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
28 Jul 2012 05:46 PM
Indeed, what's the output?
Report Abuse
kools is not online. 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 is not online. 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
Phunguy2400 is not online. Phunguy2400
Joined: 06 Sep 2009
Total Posts: 97
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
Phunguy2400 is not online. Phunguy2400
Joined: 06 Sep 2009
Total Posts: 97
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 is not online. 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
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
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 is not online. kools
Joined: 11 Jan 2009
Total Posts: 1659
28 Jul 2012 06:23 PM
Woops!
Report Abuse
kools is not online. 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 is not online. 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
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
28 Jul 2012 07:57 PM
if Enum == Enum then?
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