Hey randomsmileyface,
The best way to go about doing this would be to make a BindableEvent that fires when a players' data is changed and connect to it as needed, similar to what you suggested. Assuming we make a RemoteEvent called 'PlayerDataChanged' in ReplicatedStorage, let's do the following:
local PlayerDataChangedEvent = game.ReplicatedStorage:WaitForChild("PlayerDataChanged")
local function OnPlayerDataChanged(player, data)
if (PlayerDataChangedEvent) then
PlayerDataChangedEvent:InvokeClient(player, data)
end
end
local PlayerDataChangedEvent = game.ReplicatedStorage:WaitForChild("PlayerDataChanged")
local function OnDataChanged(data)
end
PlayerDataChangedEvent.OnClientEvent:Connect(OnDataChanged)
All that really needs to be done is to use custom events that only fire when needed. Pretty sweet. c:
Now, don't sweat yourself worrying about implementing MVC perfectly, just do your best and use it more as a tool to help you make better, more maintainable code. After all, the reason I wrote the article was to introduce people to a concept that makes their lives easier in the long run.
I don't explicitly mention this in the article, but the end goal is really to inspire people develop their own architectures that fit ROBLOX better. In truth, I chose MVC not because it was a perfect fit for ROBLOX, but because it's so easy to tweak to fit your needs. No wonder it's the basis for a lot of other widely-used architectures today (MVVM, MVA, and MVP, to name a few.)
In short, don't use MVC because tkc here told you to. Use it because it empowers you. Feel free to play around with it. c;
Have a good one, randomsmileyface, and best of luck with your game (and adventures in program architectures! :D )
Warm regards,
tkcmdr
5 comments
I've actually been developing this game for quite a long time now, over a year actually, all to fit within this MVC philosophy. Don't worry, I'm not doing this because you "told me to" - I've got thousands of lines of code prepared for the moment that it can all just come together :).
Even though you didn't directly say how animations could get integrated into this system, it seems a bit clearer now. EX: Alongside the data, a value for a certain animation is marked true and carried out by the client..
Thank you
Whoops! I assumed you were following a recent article on MVC; didn't realize you were implementing it to begin with. Glad to hear that you're using program architectures, though; it's a really good habit to get into.
Also figured you'd know to do the animations in the handler, so I didn't cover it. Sorry about that! Glad I was able to help, though. Have a good one. c;