Calling a method with a variable, not returning self

Using OOP in a module script i fire another module script with a variable like this:

Module[MyVariable]() 

The variable is named the same as a function in the Module. A problem occurs when i try and reference the variable self which should be the metatable thingy since i used a method like this

function Object:MyMethod()

but when i try and print self, it returns nil. this doesn’t happen if i reference the method in this way

Module:MyMethod()

I thought of a way around it but i didn’t do it since i feel it is sloppy, also i havent even tried it so idk if it 100% even works, wouldn’t wanna do it that way anyways. What is the best way around this?

Module[MyVariable](Module)

That’s how you would do it. When you write a function like function Object:MyMethod() it cuts out the first argument and assumes that “self” is the first.

You can call these methods like such:

Object.MyMethod(Object)

… which acts the same way as:

Object:MyMethod()
1 Like

I saw that explained in a thread yesterday when I was trying to set it up, they explained it like

a:b = a.b(a)

and my 2AM brain couldn’t comprehend it but you just explained it really well, thanks a lot!

1 Like

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