How to make a 4D table

This will show you how to make a table with 4 axis!

by idonthackbutiflame

Author Avatar

How to make a 4D lua table

So let's say you make a bot wich will solve 4D mazes. You got the code alright except for one thing:

The bot doesn't recive information about it's environment

You know that the solution for this is to use RayCast to know where the walls of the maze is, but there is another problem: RayCast only works with a 3D Value, so it won't work for your 4D maze!

So you think, and think, and eventually come up with an idea, you'll create your own 4D table

What does a fourth dimensional table look like?

Imagine a normal table, wich would look like this:

Numbers = {1,2,3,4,5}

You only need a line to represent it, like this: 1,2,3,4,5

But for example take a look at a 2D one

i = -1^(1/2)
NumbersIn0i = {0*i+0, 0*i+1,0*i+2,0*i+3,0*i+4,0*i+5}
NumbersIn1i = {1*i+0, 1*i+1,1*i+2,1*i+3,1*i+4,1*i+5}
NumbersIn2i = {2*i+0, 2*i+1,2*i+2,2*i+3,2*i+4,2*i+5}
NumbersIn3i = {3*i+0, 3*i+1,3*i+2,3*i+3,3*i+4,3*i+5}
NumbersIn4i = {4*i+0, 4*i+1,4*i+2,4*i+3,4*i+4,4*i+5}
NumbersIn5i = {5*i+0, 5*i+1,5*i+2,5*i+3,5*i+4,5*i+5}

ComplexNumbers = {NumbersIn0i,NumbersIn1i,NumbersIn2i,NumbersIn3i,NumbersIn4i,NumbersIn5i}

This is a complex number table wich requires two axis to represent each one of these numbers. NumbersInXi represent the X axis of each Y position, and ComplexNumbers join all the tables in one unique table. You can also see it's a bidimensional table due to the rectangle it appears to make when joint.

As each table has 6 children, we'd say it measures 6^2. This means that if you were to put the table on a sheet of paper, you'd get a perfect square like table.

Disclaimer: This 2D table can't work as computers can't calculate complex numbers ( i ). It'd work for a piece of paper

Now let's Imagine a 3D Table, made of 2D tables, made out of Normal Tables:

XY1Z1 = {1,2,3}
XY2Z1 = {4,5,6}
XY3Z1 = {7,8,9}
XY1Z2 = {10,11,12}
XY2Z2 = {13,14,15}
XY3Z2 = {16,17,18}
XY1Z3 = {19,20,21}
XY2Z3 = {22,23,24}
XY3Z3 = {25,26,27}
XYZ1 = {XY1Z1,XY2Z1,XY3Z1}
XYZ2 = {XY1Z2,XY2Z2,XY3Z2}
XYZ3 = {XY1Z3,XY2Z3,XY3Z3}

This might look confusing, so I'll explain it:

Imagine having a big cube, made out of 27 cubes. Each cube represents a child of each one of the first 9 tables. Meaning you made 9 lines of cubes. You take each line of cubes 3 by 3, and put them as a square of 33 cubes, meaning you make 3 squares made out of 3 lines each. Now you put each square together. This means you have a cube of 33*3, or 3^3.

The first nine tables represent lines of cubes, the 10th, 11th and 12th make the lines become squares, and the last one joins all the squares to make a cube.

here it goes

XY1Z1W1 = {"a","b"}
XY2Z1W1 = {"c","d"}
XY1Z2W1 = {"e","f"}
XY2Z2W1 = {"g","h"}
XY1Z1W2 = {"i","j"}
XY2Z1W2 = {"k","l"}
XY1Z2W2 = {"m","n"}
XY2Z2W2 = {"o","p"}
XYZ1W1 = {XY1Z1W1,XY2Z1W1}
XYZ2W1 = {XY1Z2W1,XY2Z2W1}
XYZ1W2 = {XY1Z1W2,XY2Z1W2}
XYZ2W2 = {XY1Z2W2,XY2Z2W2}

This is a 4D table of 222*2, or 2^4, as al cubes (in this case called "cells") are the same, it's called a "tesseract" "4Cube", or as nerds like me like to call it, a "Hypercube"


It can handle 16 pieces of information.

But how do i get information from it?

First, you gotta call the last table, and the W value:


Select Z


Do the same with Y and X


so if you wanna print out hello, you'd need this:


Challenge: Can you print out "lol" with this steup?


For the bot to work, you gotta make a 4D table, writing 1 as walls, and 0 as airs, and now the bot works perfectly!

View in-game to comment, award, and more!