Is there anyway to pass an objects contents with its methods and properties as a parameter to another function?

Like say I want to pass the current object to another module, the problem is when you pass self and try to print it it only returns the properties not the methods; since I need to call the method on that specific object that was passed, any ideas around this?

Only way I found out how to do it is too atatch the function directly to self where you define it in the .new function

local Class = {}
Class.__index = Class

function Class.new()
   local self = setmetatable({
      property = 'value'
   }, Class)

   function self.exampleMethod()
      -- do stuff
   end

   return self
end

return Class

Are you talking about passing objects alongside their metatables across the server-client boundary?

This is a well known and documented limitation of the engine and there’s hacky solutions to the problem, that then becomes unsustainable if you’re doing more than one inheritance.

Remote:FireAllClients(object, getmetatable(object))

this is said solution, but the problem with this is that if getmetatable(object) inherits from another class (it too has a metatable), this wouldn’t be passed. requiring you to do:

Remote:FireAllClients(object, getmetatable(object), getmetatable(getmetatable(object)))

You can start seeing the problem. This also doesn’t work with functions, as those can’t be passed across the network.

but then, since you would need to reconstruct the object from its metatable anyways, the real and practical solution is to divorce the data from its behavior

you can learn more about it in depth from this video:

1 Like

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