#Link System
1 messages · Page 1 of 1 (latest)
Ingredients are put on stations
and my current link system uses object values to keep track of what's connected to what
but this is getting hard to manage
so I'm thinking whether to keep track of sushi/connected items in general with models or tables or something else
I'd probably have the sushi manage itself, in a way.
So like one thing tells the sushi what it has.
The sushi itself updates its physical nature, like adding / removing meshes to the overall model
so like
wait lemme show you what my connection system is like
"one thing" like what?
currently it's using object values inside the part
isn't that just a model?
So like something adds an object value to say the sushi has some part
the sushi itself would listen to child added events for an object value, and then connect the various parts
Well this way the logic for adding things to a sushi doesn't have to care about how it physically gets attached, like welds or whatever
what if I use like a root part?
What do you mean?
like, the first part that gets connected would be the root part and I keep track of connections by using that part's connections
hmm maybe nvm
How do you detect if the sushi has the correct stuff on it? You said ObjectValues?
yeah
Do those object values contain the part or model that gets added?
my current system uses object values that refer to connected parts
Okay, maybe I need to better understand your current system.
Let's say an action occurs and something needs to be added, say, rice.
How does that sushi now have rice?
rice's link1 (for example) object value is set to the part it just connected to and that part's link1 (for example) object value is set to rice
Okay, so you have a base ObjectValue that's like the base.
So each object has an ObjectValue that links it to its parent?
there aren't really parents
each part is independent
each object has an ObjectValue that links it to it's currently linked part
So one sushi has many ObjectValues?
for now, one object has 2 ObjectValues
Which connects it to what's below and above?
yes
So basically it's like a double linked list
you remove a sushi and you just change the ObjectValues so they connect again
Who does the physical connections? Or is that what you were asking with this post?
- yes
- my link modules
here's one function of my link handler that links objects to each other
-- FUNCTION: Connect two objects to each other
function LinkModule.link(object: BasePart, target: BasePart): boolean
local objectSlot = LinkModule.getAvailableSlot(object)
local targetSlot = LinkModule.getAvailableSlot(target)
if not objectSlot or not targetSlot then
return false
end
local objectSlotValue = object:FindFirstChild(objectSlot)
local targetSlotValue = target:FindFirstChild(targetSlot)
if objectSlotValue and objectSlotValue:IsA("ObjectValue") then
objectSlotValue.Value = target
end
if targetSlotValue and targetSlotValue:IsA("ObjectValue") then
targetSlotValue.Value = object
end
object:SetAttribute("IsLinked", true)
target:SetAttribute("IsLinked", true)
if LinkModule.isLinkedToImmovable(object) then
object:SetAttribute("IsDraggable", false)
object.Anchored = true
target:PivotTo(object.CFrame)
end
if LinkModule.isLinkedToImmovable(target) then
target:SetAttribute("IsDraggable", false)
target.Anchored = true
object:PivotTo(target.CFrame)
end
Utilities.createWeld(object, target)
return true
end
yeah it's like a double linked list
How do you detect what the sushi has?
I also need to do whole object operations like setting the sushi type or setting the sushi value but since there's no like central value for the sushi and the sushi is defined with just ObjectValues it feels wrong.
ObjectValues
Okay, so you need some kind of object with data that's separate from its physical form.
You can have a model that represents the sushi. Maybe it has a folder of metadata, like string values and such.
Then the physical parts can live in the model.
Perhaps a module has a function that has the sushi listen for child added events in its metadata. It can then react appropriately.
Or, you can store the sushi's data in the table, like a SushiManager module
So you store the sushi's model in a table with the rest of its data
You can do something like getSushiModel(sushiTable) or getSushiTable(sushiModel)
so should I create the model/folder whenever 2 parts connect to each other or have a model/folder for every single part?
hmm alright
I'll try this tomorrow then
The idea is you always have like one sushi object to represent the whole thing, regardless of what it actually has on it. So everything is contained within it.
Oh. So would this work/fit the idea?
An invisible part inside every part that does what you said
And if so, is it a viable/good way?
(and the part would use attributes/values to do the data)
Oh wait why not just use Attributes on the model that contains all the linked sushi parts?
For the metadata at least
The system currently doesn't use models
So they're a bunch of entriely separate parts?
Yes.
Hhm. I think that'd make deleting them all harder
I'd put them in one model and use that model for attributes
But should I make the models in every part at the start or create a model when two parts are connected?
Or how should I handle that?
Create a model when a sushi is created
hard to work with ngl
Really? Why's that? If all the parts are together in the model then you have a central part you can delete and manipulate
I mean whatever works best for you but I would like the fact that I can always find the central object
because like
let's say I create a new model instance whenever 2 or more parts are connected to each other
which part is the primary part?
what if another model group connects with this model group?
like
-- FUNCTION: Creates the touch Links for ingredients/plates/stations
local function createTouchConnection(object: BasePart)
if SushiState.cookTouchConnections[object] then
return SushiState.cookTouchConnections[object]
end
local connection = object.Touched:Connect(function(hit: BasePart)
if SushiState.touchConnectionDebounce then
return
end
SushiState.touchConnectionDebounce = true
task.delay(0.15, function()
SushiState.touchConnectionDebounce = false
end)
local linkContext = object:GetAttribute("SushiType") or hit:GetAttribute("SushiType") or object:GetAttribute("ObjectType") or hit:GetAttribute("ObjectType")
local success, errorType = LinkModule.canLink(linkContext, object, hit)
if not success then
print(`{object.Name} cannot connect with {hit.Name}, error is {errorType}`)
return
end
LinkModule.link(object, hit)
end)
SushiState.cookTouchConnections[object] = connection
return connection
end
the models primary part?
do I remove all metadata on parts except ObjectValues and set all the metadata on the model?
also this
LinkModule.canLink(linkContext, object, hit)
With attributes yeah
I mean the welds can act as the link chain too, not sure you need ObjectValues
what would I use to call canLink if object is a model?
oh wait maybe I could set it on the model (the ingredients, values, etc. )
Hmm well attributes can't be like tables unfortunately
So that you may need to store. You could walk the link chain to collect the ingredients into a list I suppose
I think I'll just use attributes like hasRice, hasSeaweed, isRiceShaped, etc.
Whatever works best for you
Each ingredient can have attributes too
that kinda brings me back to my original system
Well like rice can have attributes
But the overall sushi can have unique attributes
I just think having the entire sushi contained in something makes sense, as you can just like delete the entire sushi in one go rather than deleting each ingredient, as well as being able to determine the sushi's bounding box as a whole
what kind of attributes would rice have? also I agree with your last point