|
| 14 Jul 2017 07:37 PM |
math.randomseed(tick()) local vector3s = {} function checkcframe(vector3,vectornumber) local lul = false for i,v in next, vector3s do if vector3s[vectornumber].x - vector3s[vectornumber-1].x >= 10 then if vector3s[vectornumber].z - vector3s[vectornumber-1].z >= 10 then lul = true break end end end print(lul) return lul end for i = 1,20 do wait() local Tree = game.ReplicatedStorage.Tree:Clone() local randcframe = CFrame.new(math.random(-200,200),8,math.random(-200,200)) table.insert(vector3s,randcframe.p) if i > 1 then repeat wait() local loops = i randcframe = CFrame.new(math.random(-200,200),8,math.random(-200,200)) table.insert(vector3s,randcframe.p) a = checkcframe(randcframe.p,loops) loops = loops + 1 until a == true Tree:SetPrimaryPartCFrame(workspace.PlainMap.BasePlate.AllottedTreeSpace.CFrame * randcframe) else Tree:SetPrimaryPartCFrame(workspace.PlainMap.BasePlate.AllottedTreeSpace.CFrame * randcframe) end script.FoodGenerator:Clone().Parent = Tree Tree.Parent = workspace end
lul is always false, i'm trying to compare the cframes to make sure they're not too close before placing another tree but this isn't working |
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
|
| 15 Jul 2017 09:06 PM |
I'm not sure you're doing the in next portion correctly, but I haven't used next so I'm going to give you an ipairs loop and see if that works.
for i,v in ipairs(vector3s) do --code end
Also, you're adding values to your vector3s table wrong. The current way you do it makes it so the key is 1,2,3 etc. but your indexing it as if the key were a dictionary.
|
|
|
| Report Abuse |
|
|
|
| 15 Jul 2017 09:17 PM |
| I don't get the 2nd part of that statement, and ipairs didn't work either( it also crashed me, you coulda told me it needed a wait xd ) |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2017 10:09 PM |
In this line of code: table.insert(vector3s,randcframe.p) You're putting a value into the vector3s table at vector3s[#vector3s + 1]
When you try to look at that value, you look for it at vector3s[randcframe.p] which will return nil, since right now your table is purely in array format (only integer keys).
instead of inserting into the table, a dictionary format WOULD work instead.
vector3s[randcframe.p] = randcframe.p
Except for the fact that you then try to look at that value as if it were a dictionary in: vector3s[vectornumber-1].x >= 10 then
Basically, your whole structure of the vector3s table needs to be redone.
You could either use a multi-dimensional table: www.#########################This is complex subject, and personally, I would just bruteforce it with something like this:
function checkcframe(pos) local goodEnough = true for i,v in ipairs(vector3s) do if (v-pos).magnitude <= 10 then goodEnough = false break end return goodEnough end
for i = 1,20 do wait() local Tree = game.ReplicatedStorage.Tree:Clone() repeat wait() local loops = i randcframe = CFrame.new(math.random(-200,200),8,math.random(-200,200)) table.insert(vector3s,randcframe.p) a = checkcframe(randcframe.p,loops) loops = loops + 1 until a == true Tree:SetPrimaryPartCFrame(workspace.PlainMap.BasePlate.AllottedTreeSpace.CFrame * randcframe) else Tree:SetPrimaryPartCFrame(workspace.PlainMap.BasePlate.AllottedTreeSpace.CFrame * randcframe) end script.FoodGenerator:Clone().Parent = Tree Tree.Parent = workspace end
|
|
|
| Report Abuse |
|
|
|
| 15 Jul 2017 10:10 PM |
Multi-dimensional Tables: wiki.roblox.com/index.php?title=Table#More_information
Click the link that says "11.2 - Matrices and Multi-Dimensional Arrays"
|
|
|
| Report Abuse |
|
|