OOP & Tables + use of self?

Hi, I’m working with the use of self and currently having an issue if someone is capable of shining some light on it?

I’m attempting to refer to an initial self table from within another; to elaborate on this:

self = {}
self.__index = self

self.Player = Server:GetService('Players').LocalPlayer
self.Character = self.Player.Character or self.Player.CharacterAdded:Wait(2)

for __,Module in (Script:GetChildren(...)) do
	self[Module.Name] = {}
	require(Module):init(self, ...) 
end

This is my initial code for setting it up, however going forward into the modules setup - i.e. if I have another table called ‘Camera’ for handling the Enable or Disable, when I use self it only refers to the Camera table and not the hierarchy of the self.

Does anyone perhaps have any suggestions on how to handle this?

What exactly are you trying to do though,? Usually you use OOP when you want to have multiple different objects which are relatively similiar

3 Likes

Essentially I’m working on a sort of Framework that’ll be held within PlayerScripts that’ll control things such as:

  • Moving Player between Chunks.
  • Transitions.
  • Zone detection.
  • Music control.

These are just examples however I’ll wish for them to communicate with eachother. i.e. when loading a new chunk, the transition will be called and so forth.

Outside of all these basic controls, it’ll also be able to be triggered from other scripts in the future such as storyline control etc.

1 Like

So one module script and then other module scripts as children inside it?

2 Likes

Essentially yes, all able to communicate with each other.

1 Like

I recommend watching B Ricey’s Tycoon playlist then. You get to see like the whole entire system and how it works. One thing to take away from it is the PublishTopic thing, which is what I think you will love and I think it will work perfectly for what you are asking!

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