为什么属性是“名称”?在 Roblox 中,“名称”并不存在。就像“类名”一样在代码中
我在 Roblox api 中看到了代码示例,类“Name”未用作“Name" 代码如“ClassName" 即可。你能告诉我原因吗?
例子: (类名代码)
for _, child in ipairs(game.Workspace:GetChildren()) do
if child.ClassName == "Part" then
print("Found a Part")
-- will find Parts in model, but NOT TrussParts, WedgeParts, etc
end
end
(名称代码)
local baseplate = workspace.Baseplate
local baseplate = workspace["Baseplate"]
local baseplate = workspace:FindFirstChild("BasePlate")
I saw code example in Roblox api and class "Name" wasn't used as "Name" in code like "ClassName" do. Can you tell me the reason?
example:
(ClassName code)
for _, child in ipairs(game.Workspace:GetChildren()) do
if child.ClassName == "Part" then
print("Found a Part")
-- will find Parts in model, but NOT TrussParts, WedgeParts, etc
end
end
(Name code)
local baseplate = workspace.Baseplate
local baseplate = workspace["Baseplate"]
local baseplate = workspace:FindFirstChild("BasePlate")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,如果有意义的话,ClassName 基本上就像一个“类型”。名称是为了缩小该部分的实际NAME范围。假设我有一个如下所示的工作区目录:
Workspace:
CoolPart
另一个部分
如果我这样做:
它将打印“找到零件”两次,因为 CoolPart 和 AnotherPart 都是工作区的零件(不是桁架,不是楔子,而是实际的砖块零件),但如果您这样做:
它不会打印任何内容,因为工作区中的所有内容实际上都没有标题为“部分”,您明白我的意思吗?
Alright, so a ClassName is basically like a 'Type' if that makes sense. Name is to narrow down the actual NAME of the part. So lets say I have a workspace directory that looks like this:
Workspace:
CoolPart
AnotherPart
If I do:
It will print 'Found a Part' twice, because both CoolPart and AnotherPart are a Part (not a truss, not a wedge, an actual brick part) of the workspace, but if you do:
It won't print anything, because of everything that is in workspace, none of them are actually titled 'Part', you get what I mean?
桁架零件与零件不同,因为球只是形状属性发生变化的零件。这与桁架零件不同。桁架零件虽然是基础零件,但不是零件。如果您确实想做您所做的事情,请使用:
您还应该使用
if Instance:IsA("BasePart") then...
因为它会提示/显示您可以使用的内容。A truss part is different from a part as a ball is just a part with it's shape property changed. This is NOT the same for a truss part. A truss part, although a base part, is not a part. If you do want to do what you did, use:
You should also probably use
if Instance:IsA("BasePart") then...
because it prompts / shows what you could use.