• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Properly tabbing nested tables

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
This bugs me everytime I tab tables, and I'm wondering if I'm simply not tabbing them correctly.

I'll show you how I expand and tab my tables, and hopefully someone can show me where I'm going wrong?

Code:
local config = {
    [1] = {},
    [2] = {}
}
Code:
local config = {
    [1] = {object = {
        [1] = {},
        [2] = {}
        }
    },
    [2] = {object = {
        [1] = {},
        [2] = {}
        }
    }
}
Everything lines up perfectly at this point.
If I add one more nested table, everything get's fudged up.
Code:
local config = {
    [1] = {object = {
        [1] = {object2 = {
            [1] = {},
            [2] = {}
            }
        },
        [2] = {object2 = {
            [1] = {},
            [2] = {}
            }
        }
        } -- these don't line up properly
    },
    [2] = {object = {
        [1] = {object2 = {
            [1] = {},
            [2] = {}
            }
        },
        [2] = {object2 = {
            [1] = {},
            [2] = {}
            }
        }
        } -- these don't line up properly
    }
}
Am I suppose to keep the brackets on the same line, like this?
Or how am I supposed to do it? :oops:
Code:
local config = {
    [1] = {object = {
        [1] = {object2 = {
            [1] = {},
            [2] = {}
        } },
        [2] = {object2 = {
            [1] = {},
            [2] = {}
        } }
    } },
    [2] = {object = {
        [1] = {object2 = {
            [1] = {},
            [2] = {}
        } },
        [2] = {object2 = {
            [1] = {},
            [2] = {}
        } }
    } }
}
 
i usually do it like this
Code:
local config = {
    [1] = {
        object = {
            [1] = {
                object2 = {
                    [1] = {},
                    [2] = {}
                }
            },
            [2] = {
                object2 = {
                    [1] = {},
                    [2] = {}
                }
            }     
        }
    }
}
putting the objectX = { on the same line as [index] = { will make formatting it properly really weird imo

looking at your example, i couldnt manage to get the indentation looking "proper" according to my taste, it just ends up weird with double brackets on 1 line, or on 2 consecutive lines :/

EDIT:
actually if you use something like
Code:
local config = {
    [1] = {
        ['object'] = {
            [1] = {
                ['object2'] = {
                    [1] = {},
                    [2] = {}
                }
            },
            [2] = {
                ['object2'] = {
                    [1] = {},
                    [2] = {}
                }
            }
        }
    }
}
it fits better than using object = imo
 
Last edited:
Back
Top