hey guys! Is there a way to remove the “self” argument in this function?
Here’s an image of the function I’m trying to use:
As you can see, self is clearly not defined in the arguments of this function… am I missing something?
hey guys! Is there a way to remove the “self” argument in this function?
Here’s an image of the function I’m trying to use:
As you can see, self is clearly not defined in the arguments of this function… am I missing something?
use MapModule:spawnmap() or MapModule.spawnmap(MapModule)
I replaced it with MapModule.spawnmap and it got fixed
thank you my goat…
Just to add a little context for anyone who comes here in the future.
When adding functions to a table, if you use a colon :
it silently passes the self parameter to the running function, so the first parameter of the function is going to be self, which refers to the table the function was added to, then the rest of your parameters.
Here’s a quick example:
local ourTable = {
Version = "0.1.0";
}
local ourOtherTable = {
TableName = "Our Other Table";
}
function ourTable:SetVersion(newVersion: string)
self.Version = newVersion
end
function ourOtherTable.SetTableName(self, newName: string)
self.TableName = newName
end
print(ourTable.Version)
ourTable:SetVersion("1.0.0")
print(ourTable.Version)
--You can also interchange the two. : just passes the table in as the first parameter, with a . you would need to pass the table to the function
--For example:
ourTable.SetVersion(ourTable, "1.0.1");
print(ourTable.Version)
print(ourOtherTable.TableName)
ourOtherTable.SetTableName(ourOtherTable, "Our NEW Other Table")
print(ourOtherTable.TableName)
--The same thing goes here
ourOtherTable:SetTableName("Our NEW NEW Other Table")
print(ourOtherTable.TableName)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.