错误消息说"TweenInfo.new第一个参数需要一个时间数字".使用TweenInfo时 [英] Error Message Saying "TweenInfo.new first argument expects a number for time," when using TweenInfo

查看:59
本文介绍了错误消息说"TweenInfo.new第一个参数需要一个时间数字".使用TweenInfo时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行补间,并且收到一条错误消息,提示"TweenInfo.new第一个参数期望数字表示时间".怎么了?

I am making a tween, and I am getting an Error Message saying that "TweenInfo.new first argument expects a number a number for time," what is wrong?

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语言的一个有趣的怪癖.事实证明,当仅提供一个参数时,括号在函数调用中是可选的.

You've run into a fun quirk of the lua language. As it turns out, parentheses are optional in function calls when only one argument is supplied.

所以代码中实际发生的是这个...

So what is actually happening in your code is this ...

local tweenInfo = TweenInfo.new(
    { table of arguments }, -- time
    nil, -- easing style
    nil, -- easing direction
    nil, -- repeat count
    nil, -- reverses
    nil -- delay
 )

TweenInfo构造函数期望第一个参数为数字,而是获取一个值表.

The TweenInfo constructor is expecting a number for the first argument, and instead it's getting a table of values.

要解决此问题,只需将大括号替换为括号:

So to fix this, just replace the curly brackets with parentheses:

local tweenInfo = TweenInfo.new(
    0.75,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)

-根据注释, TweenService:Create()中也存在语法错误.如果其他人也需要此修复程序,我会在此发布.

--Edit : according to the comments, there was also a syntax error in TweenService:Create(). I've posted the fix here should others need it as well.

tweenService:Create(v, tweenInfo, {
    Position = Vector3.new(X,Y,Z),
})

这篇关于错误消息说"TweenInfo.new第一个参数需要一个时间数字".使用TweenInfo时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆