I dont feel like using OOP, so i’ve been using bindables to tell enemies to attack but another bindable for when finishing the attack and I feel that it’s probably a really unsophisticated solution but i cant think of better, so can someone help me
Custom Signal classes, like GoodSignal for example: Lua Signal Class Comparison & Optimal `GoodSignal` Class
Instead of creating multiple Bindables, you can use just one and handle different actions based on a parameter
For example:
local MyBindable = script.Parent.MyBindable
MyBindable:Fire("Attack")
MyBindable:Fire("Stop")
MyBindable.Event:Connect(function(enemiesAction: string)
if enemiesAction == "Attack" then
-- ...
elseif enemiesAction == "Stop" then
-- ...
end
end)
Module Scripts are similar and I’m sure if you do your research you can learn about the pros and cons of both ![]()
That gets messy very quick, also Bindables only fire on the next frame, due to default signal behavior that is set to Deferred now. Using custom Signal classes is generally a better practice ![]()
I’ve been reading a lot on my own and I’ll keep it in mind for future projects, there’s always something new to learn ![]()
One question about this example, would you use a separate Signal for each door? Because it feels like a similar situation to the BindableEvent example
local Signal = require(script.Parent.Signal)
local DoorManager = {
Open = Signal.new()
}
function DoorManager.OpenDoor(door)
DoorManager.Open:Fire(door)
end
return DoorManager
local DoorManager = require(script.Parent.DoorManager)
DoorManager.Open:Connect(function(door)
if door == "A" then
elseif door == "B" then
end
-- ...
end)
Your best bet would be making a class for doors if you want to keep code scalable and organized. But if you want to keep it as simple as that, you could make a switch case for it.