Need help with understanding dictionary possible bug

Hello. I’m making my own plugin. But it have a bug - only last node links is “Correct”.
I think this’s due to dictionaries, so I have 1 question:

local massive = {
    a = 1,
    b = 2,
    c = 3,
}
local clone = massive

My question is: is clone cloned massive dictionary, or I just created second way to input into massive with clone?

local massive = {
    a = 1,
    b = 2,
    c = 3,
}
local clone = massive
clone.a = 5 -- will this affect massive, or clone only?

You are changing the Value inside a Dictionary, and Assigning it to something else, since a is already assigned to 1, you are now assigning it to 5

But since clone is assigned to massive, it should still affect massive

1 Like

Thx for answer!
Did you know how I can actually clone massive, but not create link to it?

There is function called table.clone()

Example:

massive = { -- Our Table
	a = 1;
	b = 2;
	c = 3;	
}

local clone = table.clone(massive) -- clones the Table


print(clone) -- Should print the cloned table as: {...}
1 Like

Hm… I tried cloning with table.clone on dictionary. But I have 1 question: it have any limits or smth else? Bc when i use it in my 7-level dictionary-array, it still changes original dictionary:

local CurrentLayout = {
	CurrentNodes = {},
	CurrentLinks = {},
}
local Nodes = {
	Generation = {
		["2D Perlin noise"] = {
			Input = {
				Order = {"Octaves", "Lacunarity", "Persistence", "Noise Scale", "Region"},
				Octaves = {3, "Input", 1, 10},
				Lacunarity = {1, "Input", 0.1, 100},
				Persistence = {0.05, "Input", 0.01, 5},
				["Noise Scale"] = {100, "Input", 1, 1000},
				--HeightScale = {100, 1, 1000},
				Region = {nil, "Link", "RegionValue", nil},
			},
			Output = {
				Generaton = {nil, "Link", "GenerationValue", {}},
			},
		},
	},
}

...

function CreateNode(var1, var2, ...)
	...
	CurrentLayout.CurrentNodes[NodeTitle] = table.clone(Nodes[Direction[1]][Direction[2]]) <-- still write into original dictionary inside Nodes
	....

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.