加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Lua是什么意思?

发布时间:2020-12-15 00:24:45 所属栏目:大数据 来源:网络整理
导读:我已经看到角色’#’被添加到变量的前面很多在Lua,我只是想知道它是做什么的?我在这里找到了一个例子. -- sort AIs in currentleveltable.sort(level.ais,function(a,b) return a.y b.y end)local curAIIndex = 1local maxAIIndex = #level.aisfor i = 1,#c
我已经看到角色’#’被添加到变量的前面很多在Lua,我只是想知道它是做什么的?我在这里找到了一个例子.
-- sort AIs in currentlevel
table.sort(level.ais,function(a,b) return a.y < b.y end)
local curAIIndex = 1
local maxAIIndex = #level.ais
for i = 1,#currentLevel+maxAIIndex do
    if level.ais[curAIIndex].y+sprites.monster:getHeight() < currentLevel[i].lowerY then
        table.insert(currentLevel,i,level.ais[curAIIndex])
        curAIIndex = curAIIndex + 1
        if curAIIndex > maxAIIndex then
            break
        end
    end
end

道歉如果这已经被问到,我已经在互联网上搜索了很多,但我似乎没有找到答案.提前致谢!

解决方法

那就是 length operator:

The length operator is denoted by the unary operator #. The length of a string is its number of bytes (that is,the usual meaning of string length when each character is one byte).

The length of a table t is defined to be any integer index n such that t[n] is not nil and t[n+1] is nil; moreover,if t[1] is nil,n can be zero. For a regular array,with non-nil values from 1 to a given n,its length is exactly that n,the index of its last value. If the array has “holes” (that is,nil values between other non-nil values),then #t can be any of the indices that directly precedes a nil value (that is,it may consider any such nil value as the end of the array).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读