badfitz67
|
  |
| Joined: 03 Jun 2010 |
| Total Posts: 13165 |
|
|
| 13 Jan 2016 12:22 PM |
I made a puzzle game shown here: http://www.roblox.com/games/342564215/Puzzle
and I need a better way of getting the blocks around the clicked block
I came up with this:
local ab = v.Position + Vector3.new(2,0,0) local be = v.Position - Vector3.new(2,0,0) local le = v.Position - Vector3.new(0,0,2) local ri = v.Position + Vector3.new(0,0,2)
for _, c in pairs(sp:GetChildren()) do if c:IsA("Part") then if c.Position == Vector3.new(math.floor(ab.X),ab.Y,math.floor(ab.Z)) then ab = c.Name elseif c.Position == Vector3.new(math.floor(be.X),be.Y,math.floor(be.Z)) then be = c.Name elseif c.Position == Vector3.new(math.floor(le.X),le.Y,math.floor(le.Z)) then le = c.Name elseif c.Position == Vector3.new(math.floor(ri.X),le.Y,math.floor(ri.Z)) then le = c.Name end end end It works fine but sometimes the left block next to the clicked block wont turn green.
I've printed le and ri and I got this: 39, 4.14999962, 12.999999
I tried to use math.floor: for _, c in pairs(sp:GetChildren()) do if c:IsA("Part") then if c.Position == Vector3.new(math.floor(ab.X),ab.Y,math.floor(ab.Z)) then ab = c.Name elseif c.Position == Vector3.new(math.floor(be.X),be.Y,math.floor(be.Z)) then be = c.Name elseif c.Position == Vector3.new(math.floor(le.X),le.Y,math.floor(le.Z)) then le = c.Name elseif c.Position == Vector3.new(math.floor(ri.X),ri.Y,math.floor(ri.Z)) then ri = c.Name end end end but I get this error:
18:21:56.533 - Workspace.Model.Script:22: bad argument #1 to 'floor' (number expected, got nil) 18:21:56.533 - Script 'Workspace.Model.Script', Line 22 18:21:56.533 - Stack End
You're a blunt tool, old man. |
|
|
| Report Abuse |
|
|
Orced
|
  |
| Joined: 08 Apr 2010 |
| Total Posts: 1301 |
|
|
| 13 Jan 2016 12:28 PM |
Firstable, better use CFrame instead of Vector3. Vector3 sometimes messes things up and doesnt place the part where you want it to be. But the system is the same. Secondable, math.floor(ab.CFrame.Z) --< or Vector3.Z, depends if you listen to me or not |
|
|
| Report Abuse |
|
|
|
| 13 Jan 2016 01:20 PM |
1. You're replacing the variables with a string (don't know why it's saying nil though) 2. That's horribly inefficient |
|
|
| Report Abuse |
|
|
badfitz67
|
  |
| Joined: 03 Jun 2010 |
| Total Posts: 13165 |
|
|
| 13 Jan 2016 01:24 PM |
"Inefficient"
hence this thread
You're a blunt tool, old man. |
|
|
| Report Abuse |
|
|
|
| 13 Jan 2016 01:30 PM |
Workspace -Parts (Model) --1 (Model, yPos) ---1_1 (Part, xPos_zPos) |
|
|
| Report Abuse |
|
|
badfitz67
|
  |
| Joined: 03 Jun 2010 |
| Total Posts: 13165 |
|
|
| 13 Jan 2016 01:35 PM |
changed back to an old way of doing it:
local ab = tostring(tonumber(v.Name)-4) local be = tostring(tonumber(v.Name)+4) local le = tostring(tonumber(v.Name)-1) local ri = tostring(tonumber(v.Name)+1) if v.Name == "5" or v.Name == "9" or v.Name == "13" then print("HI!") le = nil elseif v.Name == "4" or v.Name == "8" or v.Name == "12" then ri = nil end
it works fine but I want to get rid of the if statement(if possible without changing what I'm doing to get the blocks around it), it's there to stop glitches like this:
https://twitter.com/DucktorCid/status/687356907284238337
You're a blunt tool, old man. |
|
|
| Report Abuse |
|
|
badfitz67
|
  |
| Joined: 03 Jun 2010 |
| Total Posts: 13165 |
|
|
| 13 Jan 2016 02:51 PM |
b
You're a blunt tool, old man. |
|
|
| Report Abuse |
|
|