generic image
Processing...
  • Games
  • Catalog
  • Develop
  • ROBUX
  • Search in People
  • 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 » Scripters
Home Search
 

random placement script not working

Previous Thread :: Next Thread 
masterblokz is online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9400
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
masterblokz is online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9400
14 Jul 2017 08:06 PM
b
Report Abuse
masterblokz is online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9400
14 Jul 2017 08:18 PM
n
Report Abuse
masterblokz is online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9400
14 Jul 2017 09:49 PM
b
Report Abuse
masterblokz is online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9400
15 Jul 2017 08:59 PM
b
Report Abuse
ExtremeBuilder15 is not online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 2366
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
masterblokz is online. masterblokz
Joined: 17 Nov 2010
Total Posts: 9400
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
ExtremeBuilder15 is not online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 2366
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
ExtremeBuilder15 is not online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 2366
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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.

Thanks for playing ROBLOX

  • 1

    Click RobloxPlayer.exe to run the ROBLOX installer, which just downloaded via your web browser.

  • 2

    Click Run when prompted by your computer to begin the installation process.

  • 3

    Click Ok once you've successfully installed ROBLOX.

  • 4

    After installation, click Play below to join the action!

    Play
The ROBLOX installer should download shortly. If it doesn’t, start the download now.
generic image