How to make a value inside a table dictionary reference another value in the same table dictionary?

Not sure if this is even possible.

Originally, I had these inside the script that now requires this modulescript. The script was getting too big, so I decided to put all of this into this modulescript. The problem was that before, I had these tables as separate tables, so I could use values from the previous table onto the next table. When I transferred them into this modulescript, the tables were inside the same dictionary, thus tables not being able to use values from other tables.

Inside the modulescript:

local config = {
    obj = {		
        particle = ReplicatedStorage:WaitForChild("Glass")
        num = 20
	},
	
	settings = {
		Default = {value = config.obj.particle, numberOfParticles = config.obj.particle},
	}
}
return config

How would I make it so that in the “default” table that is inside the settings table, I can reference values inside the “obj” table?

You can not accomplish this in one step, as far as I know. I would try to do this by defining config twice. You will first define it once, without default values, and then the second time you can refer to the values inside obj, since then are now reference-able.

Example:

local config = {
    obj = {		
        particle = ReplicatedStorage:WaitForChild("Glass")
        num = 20
	},
	
	settings = {
		Default = {value = nil, numberOfParticles = nil}
	}
}

config[2] = { --reset default with values from table
	Default = {value = config.obj.particle, numberOfParticles = config.obj.particles}
}

return config

This has not been tested, but is just an example of how I would go about this.

1 Like