Why is this working?

function SWRP:CreateRank(ply, rank)
        --this inserts a table called rank inside the global table SWRP.Factions
	for k, faction in pairs(SWRP.Factions) do
		if faction.id == rank.factionID then
			table.insert(SWRP.Factions[k]["ranks"], rank)

        --doing this will edit the entry in the global SWRP.Factions table which has been created earlier. Why is this working?
        rank["armor"] = 40 -- => SWRP.Factions[...][armor] will be 40 now but why? Shouldn't it only edit the local table named rank?

lua variables are kept by reference, not by instance, look into


Ah, thanks for the information. It really helped me understanding how this works! :slight_smile:

[editline]13th September 2016[/editline]

So, this

table.insert(SWRP.Factions[k]["ranks"], rank)

is creating a reference between ranks and SWRP.Factions[k][“ranks”]?
If I would edit SWRP.Factions[k][“ranks”], would it affect ranks too?