Lesson 29 of 55
9 mins readPython Nested Tables & Multi-Dimensional Matrices
In Plain English
Nested tables allow representing multi-dimensional matrices (`grid[r][c]`), trees, and complex hierarchical records like JSON data trees.
Deep Dive: How It Works
2D Array Syntax: `local matrix = { {1, 2}, {3, 4} }` accessed as `matrix[row][col]`.
Dynamic Row Creation: Initialize inner tables dynamically in loops before assignment.
Record Hierarchy: Nesting dictionaries inside arrays for database-like row records.
Core Rules to Remember

Multi-Dimensional Access: Chain index brackets: `matrix[r][c]`.

Deep Nesting: Models JSON objects and graph node structures naturally.
Live Interactive Example
Hit Run Code to see it live2D Grid Traversal
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Output Console
Click "Run Code" to view the rendered output.
How it works: Navigated the 2D grid using chained row and column indices.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Access Nested Player Record
Declare `local game = { player = { name = "Hero", stats = { hp = 100, mp = 50 } } }`.
Print `"Player " .. game.player.name .. " HP: " .. game.player.stats.hp`.
1
2
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.