使用 TweenInfo 时出现错误消息 "TweenInfo.new first argument expects a number for time,"
Error Message Saying "TweenInfo.new first argument expects a number for time," when using TweenInfo
我正在制作一个补间,但我收到一条错误消息,指出“TweenInfo.new 第一个参数需要一个时间数字”,有什么问题吗?
local tweenInfo = TweenInfo.new{
0.75,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
}
-- later on when I call it
tweenService:Create(v, tweenInfo, Vector3.new(X,Y,Z)) -- v is an Instance of a Part
请帮帮我!
您 运行 发现了 lua 语言的一个有趣怪癖。事实证明,当只提供一个参数时,parentheses are optional in function calls。
所以你的代码中实际发生的是这个...
local tweenInfo = TweenInfo.new(
{ table of arguments }, -- time
nil, -- easing style
nil, -- easing direction
nil, -- repeat count
nil, -- reverses
nil -- delay
)
TweenInfo 构造函数期望第一个参数是一个数字,但它得到的是 table 个值。
所以要解决这个问题,只需将大括号替换为圆括号即可:
local tweenInfo = TweenInfo.new(
0.75,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
--编辑:根据评论,TweenService:Create()
中也存在语法错误。如果其他人也需要,我已经在此处发布了修复程序。
tweenService:Create(v, tweenInfo, {
Position = Vector3.new(X,Y,Z),
})
我正在制作一个补间,但我收到一条错误消息,指出“TweenInfo.new 第一个参数需要一个时间数字”,有什么问题吗?
local tweenInfo = TweenInfo.new{
0.75,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
}
-- later on when I call it
tweenService:Create(v, tweenInfo, Vector3.new(X,Y,Z)) -- v is an Instance of a Part
请帮帮我!
您 运行 发现了 lua 语言的一个有趣怪癖。事实证明,当只提供一个参数时,parentheses are optional in function calls。
所以你的代码中实际发生的是这个...
local tweenInfo = TweenInfo.new(
{ table of arguments }, -- time
nil, -- easing style
nil, -- easing direction
nil, -- repeat count
nil, -- reverses
nil -- delay
)
TweenInfo 构造函数期望第一个参数是一个数字,但它得到的是 table 个值。
所以要解决这个问题,只需将大括号替换为圆括号即可:
local tweenInfo = TweenInfo.new(
0.75,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
--编辑:根据评论,TweenService:Create()
中也存在语法错误。如果其他人也需要,我已经在此处发布了修复程序。
tweenService:Create(v, tweenInfo, {
Position = Vector3.new(X,Y,Z),
})