Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Best practices for storing and retrieving 3D Co-ordinates?

Please understand I am very new to coding/scripting. I will use very inefficient methods

I am creating a mining game.

When a player causes a block in the game to be generated, I want to store its positional value so that way further block generation does not place a block in a place where a block already is.

So far I am limiting the mining size to an area so that way I can store the positional data as an Integer (600600600 for instance would equate to a block existing in X: 3600 Y: 3600 Z: 3600 (the blocks are 6x6x6))

But storing as an int value here is inefficient, because intValues also have names, so I'm storing both an int and a string at least, if not more.

I was thinking of using a table, but I have no concept of how large a table can be before checking values in a table becomes slow and inefficient. Bonus points if you can answer this!

I was reading something about a solution where you store the co-ords in the following manner:

Store X co-ordinate in main table. Have each Y value that has been checked in its own sub table and then the Z value is a sub table off the Y table

This means the tables are only ever as large as the X co-ordinate for lookup purposes, but it requires both additional checks during block generation, and it means you're looking up three tables each time.

Someone has suggested me to use bitbuffer But I read the documentation on that, and it's a little daunting for someone so new as myself.

1 comment

0

Omg, I have the same question.

1 answer

Store it in a table while using Vector3's, or a string of the Vector3(if Lua tables look at the actual instance instead of the Vector's value) as a key.

--ServerScript-->Script
local coords = {}
local addCoord = Instance.new("RemoteFunction",game.ReplicatedStorage)
local removeCoord = Instance.new("RemoteFunction",game.ReplicatedStorage)
local cellSize = Vector3.new(6,6,6)

function findVector(vector)
	return coords[vector/cellSize]
end

function addCoord.OnServerInvoke(ply,vector)
	if not findVector(vector) then
		coords[vector] = true
		return true
	end
	return false
end
function removeCoord.OnServerInvoke(ply,vector)
	if findVector(vector) then
		coords[vector] = false
		return true
	end
	return false
end

This discussion is preserved as it was. New answers, comments, and votes are closed.