【问题标题】:Attempt to index field '_target' (a number value)尝试索引字段“_target”(数字值)
【发布时间】:2013-09-11 23:13:45
【问题描述】:

我正在尝试修改删除功能,但收到此错误:

Attempt to index field '_target' (a number value)

代码sn-p:

   for i = #badC1T, 1, -1 do
        if badC1T[i] ~= nil then

            transition.to( i, {  time=500, alpha=0,} )

            local function dellBadC1T()
                badC1T[i]:removeSelf()
                badC1T[i] = nil
            end

            timer.performWithDelay( 500, dellBadC1T, 1 )
        end
    end

知道如何解决这个问题吗?

【问题讨论】:

  • badC1T数组的内容是什么?你确定你的意思是badC1T[i]:removeSelf(),而不是badC1T[i].removeSelf()
  • @Kamiccolo removeSelf 函数的工作原理是产生错误的“transition.to( i, { time=500, alpha=0,} )'
  • 根据documentation,您应该将Target object 作为第一个参数传递给transitio.to()。所以,它可能是badC1T[i] 而不是i。可能是transition.to( badC1T[i], { time=500, alpha=0,} )。真的不能说,除非您提供有关badC1T 内容的信息。
  • @Kamiccolo 你的正确 transition.to(badC1T[i], { time=500, alpha=0,} ) 就像一个魅力:D

标签: lua coronasdk


【解决方案1】:

根据CoronaSDK documentation 的第一个参数transition.to() 必须Target object。但是你传递了一个数字i

修复可能如下所示:

transition.to( badC1T[i], { time=500, alpha=0,} )

【讨论】:

    猜你喜欢
    • 2012-03-12
    • 2020-05-28
    • 1970-01-01
    • 2019-10-10
    • 2013-06-18
    • 2011-11-05
    • 2018-12-30
    相关资源
    最近更新 更多