User:Hajo/test2

From Minetest

Table-test2

x,y,z

Lua - Online-IDEs

Example - Formatting a table:

Prog1

http://ideone.com/1fhw6j

 -- table x,y,z
 n=1
 y=0
 for x = -n, n do
  for z = -n, n do
  --print(x,y,z)
    print( string.format("%3d %2d %2d", x,y,z) )
  end
 end
Output
-1  0 -1
-1  0  0
-1  0  1
 0  0 -1
 0  0  0
 0  0  1
 1  0 -1
 1  0  0
 1  0  1

Prog2

http://ideone.com/nbSPkn

-- table x,y,z --> w
 function w(x,y,z)
 	c="black"
 	if z<0 then c="red" end
 	return c
 end
 
 n=1
 y=0
 for x = -n, n do
  for z = -n, n do
    c=w(x,y,z)
  --print(x,y,z, c)
    print( string.format("%3d %2d %2d %s", x,y,z, c) )
  end
end
Output
-1  0 -1 red
-1  0  0 black
-1  0  1 black
 0  0 -1 red
 0  0  0 black
 0  0  1 black
 1  0 -1 red
 1  0  0 black
 1  0  1 black