#Link System

1 messages · Page 1 of 1 (latest)

zealous folio
#

How should I handle this:

A sushi making system that links/welds parts together to create the sushi and keeps track of them so that I can put values on them when they're completed. But I'm not sure whether to use models and create new models when parts connect to each other or something else.

zealous folio
#

and my current link system uses object values to keep track of what's connected to what

zealous folio
#

so I'm thinking whether to keep track of sushi/connected items in general with models or tables or something else

inner geode
zealous folio
#

wait lemme show you what my connection system is like

zealous folio
#

currently it's using object values inside the part

inner geode
# zealous folio "one thing" like what?

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

inner geode
zealous folio
#

what if I use like a root part?

inner geode
zealous folio
# inner geode 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

inner geode
inner geode
zealous folio
inner geode
zealous folio
inner geode
zealous folio
#

each part is independent

#

each object has an ObjectValue that links it to it's currently linked part

inner geode
zealous folio
inner geode
zealous folio
inner geode
# zealous folio 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?

zealous folio
#

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
zealous folio
inner geode
zealous folio
#

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.

zealous folio
inner geode
# zealous folio 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)

zealous folio
zealous folio
#

I'll try this tomorrow then

inner geode
zealous folio
zealous folio
inner geode
#

For the metadata at least

zealous folio
inner geode
zealous folio
inner geode
# zealous folio Yes.

Hhm. I think that'd make deleting them all harder

I'd put them in one model and use that model for attributes

zealous folio
zealous folio
inner geode
zealous folio
inner geode
# zealous folio 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

zealous folio
#

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
zealous folio
#

also this

LinkModule.canLink(linkContext, object, hit)
inner geode
zealous folio
#

oh wait maybe I could set it on the model (the ingredients, values, etc. )

inner geode
zealous folio
inner geode
zealous folio
inner geode
# zealous folio 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

zealous folio