我已经看到在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
Run Code Online (Sandbox Code Playgroud)
如果已经有人问过这个道歉,我已经在互联网上搜索了很多,但我似乎没有找到答案.提前致谢!
我只是有一个普遍的问题.
在Lua中使用单引号和双引号有什么区别吗?
例:
require('test.lua')
require("test.lua")
Run Code Online (Sandbox Code Playgroud)
当我在PAWN中编程,一种类似于C的语言时,单引号可用于字符,但不能用于文本字符串,您必须为它们使用双引号.
如果没有差异,建议使用哪一个?
这个问题很可能已经得到了解答,但是我找不到已回答的话题.
谢谢.
我有一个新问题,我想知道你是否能够在Lua内做enumartions,我不确定这是否是正确的名称,我能解释的最佳方式是如果我给你看一个例子使用PAWN(如果您知道C类型语言,那将是有意义的).
#define MAX_SPIDERS 1000
new spawnedSpiders;
enum _spiderData {
spiderX,
spiderY,
bool:spiderDead
}
new SpiderData[MAX_SPIDERS][_spiderData];
stock SpawnSpider(x, y)
{
spawnedSpiders++;
new thisId = spawnedSpiders;
SpiderData[thisId][spiderX] = x;
SpiderData[thisId][spiderY] = y;
SpiderData[thisId][spiderDead] = false;
return thisId;
}
Run Code Online (Sandbox Code Playgroud)
这就是它在PAWN中的样子,但我不知道如何在Lua中这样做......这就是我到目前为止所做的.
local spawnedSpiders = {x, y, dead}
local spawnCount = 0
function spider.spawn(tilex, tiley)
spawnCount = spawnCount + 1
local thisId = spawnCount
spawnedSpiders[thisId].x = tilex
spawnedSpiders[thisId].y = tiley
spawnedSpiders[thisId].dead = false
return thisId
end
Run Code Online (Sandbox Code Playgroud)
但显然它会出错,你们中有谁知道这样做的正确方法吗?谢谢!
randomString.lua
----------------------------------------------------------------------------
-- File: randomString.lua
-- Author: Don Draper
--
-- This is the Lua implementation of my simple 'randomString' function
-- which I previous wrote in PAWN.
----------------------------------------------------------------------------
randomString = {}
local randomCharset = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", …
Run Code Online (Sandbox Code Playgroud)