Problem with Fusion

ok so im using Fusion and when i try to do this (not the actual code)

local moduleValue = Value (somemodule)

New "TextLabel" {
    Text = Computed(function()
        local module = moduleValue:get()
        
        return module.Source
    end)
}

and change the module’s source, it doesn’t update the text, instead it only updates if moduleValue's value is changed. i tried to store the module’s source in a separate value object but i just couldn’t figure it out

3 Likes

Pretty sure you can just pass the module Source directly like this:

local moduleValue = Value(somemodule.Source)

New "TextLabel" {
    Text = moduleValue,
}

no, thats not how it works, it wouldn’t update

did you try it?

Changing a table inside a Value doesn’t update any dependencies of that Value. To update the dependencies, you must call :set() on the Value.

What you can do depends on how much control you have over the module. You could modify somemodule.Source to be a StateObject, in which case you could just directly set it inside of the New.

New "TextLabel" {
    Text = somemodule.Source
}

If you can’t modify the module, see if the module has some way to listen for changes to the Source property, and instead use a Value that you call :set on with the new Source every time it changes.

If the module doesn’t have a way to listen to changes, the only way would be to poll for it every frame, but I don’t recommend this option.

2 Likes

ok, i just found this StateObject called Observer and i think its what i need

yeah i did

If you have an observer you still need to update the state value and at that point might aswell use the value directly

1 Like

yeah, thats what im currently trying to do, the thing is the module can change depending on the user

Well, that’s the point of fusion really. Whenever the module source changes, just do moduleSource:Set(module.Source)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.