好吧我想在Lua中动态创建一个表,只要Lua生病就是第一个告诉你我是史诗n00b,但是在php中我可以创建我需要的lua表,php代码是:
<?php
$height = 50;
$widthl = -25;
$widthr = 25;
$depth = 3;
echo "tbm.offsets = { -- Facedir indexed +1\n";
echo " { --Facedir = 0 \n";
for ($x = $height; $x >= -1 ; $x--) {
echo " { -- $x \n";
for ($y = $widthl; $y <= $widthr; $y++) {
for ($z = 1; $z <= 1; $z++) {
echo " { X = ".$y.", Y = ".$x.", Z = ".$z." }, \n";
}
}
echo " },\n";
}
echo " },\n";
echo " { --Facedir = 1 \n";
for ($x = $height; $x >= -1 ; $x--) {
echo " { -- $x \n";
for ($y = $widthl; $y <= $widthr; $y++) {
for ($z = 1; $z <= 1; $z++) {
echo " { X = ".$z.", Y = ".$x.", Z = ".$y." }, \n";
}
}
echo " },\n";
}
echo " },\n";
echo " { --Facedir = 2 \n";
for ($x = $height; $x >= -1 ; $x--) {
echo " { -- $x \n";
for ($y = $widthl; $y <= $widthr; $y++) {
for ($z = -1; $z <= -1; $z++) {
echo " { X = ".$y.", Y = ".$x.", Z = ".$z." }, \n";
}
}
echo " },\n";
}
echo " },\n";
echo " { --Facedir = 3 \n";
for ($x = $height; $x >= -1 ; $x--) {
echo " { -- $x \n";
for ($y = $widthl; $y <= $widthr; $y++) {
for ($z = -1; $z <= -1; $z++) {
echo " { X = ".$z.", Y = ".$x.", Z = ".$y." }, \n";
}
}
echo " },\n";
}
echo " },\n";
echo "} \n";
?>
该代码创建了一个完美的静态lua表:但是现在我正在尝试直接在lua中执行它,并且由于这里的另一个帖子我有一个很好的开始,但新问题是当我将表分配到另一个表时在lua中它实际上添加了一个不必要的附加表,我拥有的lua代码是:
local tbmoffsets = {}
local facedir = {}
local unit = {}
local row = {}
Z1=1
for Y1 = 2, -1,-1 do
for X1 = -1,1 do
row[X1] = {X = X1, Y = Y1, Z = Z1}
end
unit[Y1]={row}
end
facedir[0] = {unit}
--additonal facedirs
tbmoffsets[0] = {facedir}
这个输出表如下所示:
0:
1: <------- unnecessary
0:
1: <------- unnecessary
1:
1: <------- unnecessary
1:
Y: -1
Z: 1
X: 1
0:
Y: -1
Z: 1
X: 0
-1:
Y: -1
Z: 1
X: -1
2:
1: <------- unnecessary
1:
Y: -1
Z: 1
X: 1
0:
Y: -1
Z: 1
X: 0
-1:
Y: -1
Z: 1
X: -1
0:
1: <------- unnecessary
1:
Y: -1
Z: 1
X: 1
0:
Y: -1
Z: 1
X: 0
-1:
Y: -1
Z: 1
X: -1
-1:
1:
1:
Y: -1
Z: 1
X: 1
0:
Y: -1
Z: 1
X: 0
-1:
Y: -1
Z: 1
X: -1
我标记了它自动放入&lt; -------不必要的表的位置,有人可以解释它为什么会这样做吗?
好吧我明白了,但我的回复高到足以回答我自己的问题......所以这是答案
Z1=1
for Y1 = 2, -1,-1 do
for X1 = -1,1 do
row[X1] = {X = X1, Y = Y1, Z = Z1}
end
unit[Y1]={row} <--- these parentheses create the extra table
end
facedir[0] = {unit} <--- these parentheses create the extra table
--additonal facedirs
tbmoffsets[0] = {facedir} <--- these parentheses create the extra table
有时候我猜你是自己最好的导师...... lmao