So I’m working on managing a placement system, under certain scenarios people should not be able to start and end an object’s placement. In order to do this, I need to bar the placement using a variable or something similar. The problem is that with the way my UI objects and build mode controller are set up, it causes the modules to be required recursively.
So, as some background, I have the main build mode controller, “BuildModeHandler” and my UI object controllers as the children of the build mode controller (GridSlider) so it’s laid out like the following:
The problem is that inside of “BuildModeHandler” there are constant variables that point to GridSlider (BuildModeHandler.GridSlider = require(script.GridSlider)
). Now, I need to update a variable inside of BuildModeHandler from GridSlider when the mouse is inside of GridSlider, thus creating a cyclic dependency.
To fix this, I can just make a third module called “status”, however this is a bandaid method and is not really ideal. In my case, the best case scenario would be to have no external dependency, eg. no value objects, no attributes, no third module, just the two modules. Is this possible?
Relevant part of the script for reference, GridSlider is the grid slider object, an object that represents multiple UI objects but visually looks like a slider element:
module.GridSlider = require(script:WaitForChild('GridSlider'))
module.GridSlider:UpdateValue(2.5)
module.GridSlider.ValueChanged:Connect(function(value)
module:AdjustGridSize(value)
end)
Inside of GridSlider, this will cause an error in the output:
local buildModeHandler = require(script.Parent)
gridSize.MouseEnter:Connect(function()
buildModeHandler.BarPlacement = true
end)
Now, the solution would appear to be this:
gridSize.MouseEnter:Connect(function()
require(script.Parent).BarPlacement = true
end)
Sure, this works, but is not ideal for a few reasons:
1- Every time the mouse enters the UI object, a call to require the module is made.
2- Won’t work if for some reason the module’s ancestry is changed.
3- There is still a warning:
Any other ideas?