Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I edit a value in a table within a table?

Here's an example of what I'm trying to do:

local table = {
	poop = {
		poops = 5
	},

	poopFunction = function()
		table.poop.poops = 10
	end
}

1 answer

Using your example, you just wanna call the function and that will work without errors.

local table = {
    poop = {
        poops = 5
    },

    poopFunction = function()
        table.poop.poops = 10
    end
}

table.poopFunction() -- will run the function

Or you could use metatables, which can access the self keyword.

local table = {
    poop = {
        poops = 5
    }
}

table.__index = table

function table:poopFunction()
     self.poop.poops = 10
end

table:poopFunction() -- will run the function

Most basic explanation is, the self keyword refers to the table in which the function is located within.

4 comments

1

I already know how to do that I want a table to edit itself though

1

I don't think that's what he wanted. What you are posting makes no sense and your explanation doesn't make sense either. You should've just posted the documentation

0

That's what it's doing - editing itself. I don't get what you are trying to say.

0

The question doesn't make sense, you're asking how to edit a value in a table that is inside of a table, which is what he did. Try explaining it a bit better.

This discussion is preserved as it was. New answers, comments, and votes are closed.