Can you send the script here so I can take a look?
Forgot to include, I’ve updated the API Reference a little bit to show the properties in a better style.
This is the script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local ClassPP = require(ReplicatedStorage["Class++"])
local class = ClassPP.class
local toolClass = class "Tool" {
constructor = function(self, tool)
if tool and tool:IsA("Tool") then
self.Tool = tool
self.Configuration = require(self.Tool.Config)
self.Tool.Equipped:Connect(function()
self.equipped = true
end)
self.Tool.Unequipped:Connect(function()
self.equipped = false
end)
end
end,
Public = {
equipped = false,
Tool = nil,
Configuration = {},
}
}
CollectionService:GetInstanceAddedSignal("Tool"):Connect(function(tool)
if tool:IsA("Tool") then
local newTool = toolClass.new(tool)
end
end)
This is the Error : {Class++}: This class has no member named "Tool".
I see what you mean now, this is a common mistake that people encounter when creating classes using my module.
This is mostly related on how dictionaries work in Luau, when you set a key to nil
, you’re actually removing that key from the table. In this case, the key Tool
is being set to nil in the Public
access specifier, and since you’re setting the key Tool
to nil
, Lua automatically removes it from the table, which in the final classData
, the Tool
member does not exist.
To solve this issue, instead of setting it to nil
, you can set it to false
.
Here’s your updated code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local ClassPP = require(ReplicatedStorage["Class++"])
local class = ClassPP.class
local toolClass = class "Tool" {
constructor = function(self, tool)
if tool and tool:IsA("Tool") then
self.Tool = tool
self.Configuration = require(tool.Config)
self.Tool.Equipped:Connect(function()
self.equipped = true
end)
self.Tool.Unequipped:Connect(function()
self.equipped = false
end)
end
end,
Public = {
equipped = false,
Tool = false,
Configuration = {},
}
}
Oh man i didnt know this about dictionaries, thank you.
Release Beta 1.4.0
- Performance improvements.
- Fixed some bugs.
- Updated the final method to support functions with the syntax below:
local class, final = ClassPP.class, ClassPP.final
local Test = class "Test" {
Public = {
test = final(function(self, ...)
print(self, ...)
end),
}
}
A performance comparison picture between 1.3.1 and 1.4.0: