Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Reference another index inside the same table

Asked by 10 years ago

Okay, this is just an example of what I intend to use this for. I plan on using something like this to edit GUIs when the mouse enters, leaves or clicks it. For now I'm just testing it out so... I want data[Workspace.BasePlate].Properties to equal data[Workspace.Part].Properties. How can I reference it from inside the table without typing it twice?

local data = {
    [Workspace.Part] = {
        Properties = {
            ["BrickColor"] = "Lime green",
            ["Material"] = "DiamondPlate"
        }
    },
    [Workspace.BasePlate] = {
        Properties = {} -- I want the properties here to be the same as Part's
    },
}

1 answer

Log in to vote
0
Answered by
jobro13 980 Moderation Voter
10 years ago

You can't do this on the initial "set" operation. However, you can do it like this:

local data = {
    [Workspace.Part] = {
        Properties = {
            ["BrickColor"] = "Lime green",
            ["Material"] = "DiamondPlate"
        }
    },
}

data[Workspace.BasePlate] = {
        Properties = data[Workspace.Part].Properties
    },
0
Oh alrighty then! Thanks! chairman154 10 — 10y
0
Just a note; if you try to do it in the first "set" operation, it won't work: at that point the index is still nil and the script will error! jobro13 980 — 10y
Ad

Answer this question