DUDE I CANT LEAVE IT AS IT IS. IT MAKES ME SO MAD, IM SO ANGRY.
Basically
local field = {}
local logic = {}
logic.__index = logic
logic.__newindex = function(self, i, v)
if i == "Strength" then
self.HealthRegen = 1 + v
self.DamageBoost = 0 + v * 5
self.PhysicalDamage = 0 + v * 2
hum.MaxHealth = 500 + v * 100
elseif i == "Agility" then
self.Defence = 1 + v
self.MovementSpeed = 16 + v
self.AttackSpeed = 5 + v * 2
self.RangedDamage = 0 + v
...
elseif i == "MovementSpeed" then
hum.WalkSpeed = v
end
rawset(self, i, v)
end
local att = setmetatable(field, logic)
att.Agility = 50;
HAPPENS NOTHING, THIS STUPID METHAMETHOD WONT RUN
BUT IF ILL DO
...
elseif i == "MovementSpeed" then
hum.WalkSpeed = v
else
rawset(self, i, v)
end
IT WILL WORK BUT WONT SHOW ME CHANGES I JUST DID IN THE TABLE.
IT WONT SHOW ME HOW THE MOVEMENTSPEED VARIABLE CHANGED. DUDES I BEG YOU FOR HELP!!
I think this problem is being caused by the fact the __newindex metamethod is only called the first time a new index is presented to the table. There’s a method for getting all accesses to the table: Programming in Lua : 13.4.4
This method can be implemented in your case like this:
--Create a unique index for the proxy table
local index = newproxy()
local field = {}
field[index] = {}
local logic = {}
logic.__index = function(self, i)
--Access the proxy table
return rawget(self[index], i)
end
logic.__newindex = function(self, i, v)
if i == "Strength" then
self.HealthRegen = 1 + v
self.DamageBoost = 0 + v * 5
self.PhysicalDamage = 0 + v * 2
hum.MaxHealth = 500 + v * 100
elseif i == "Agility" then
self.Defence = 1 + v
self.MovementSpeed = 16 + v
self.AttackSpeed = 5 + v * 2
self.RangedDamage = 0 + v
end
--Add this to the proxy table so every time access it normally, the __newindex function will be called
rawset(self[index], i, v)
end
local att = setmetatable(field, logic)
att.Agility = 50;
print(att.Defence, att.MovementSpeed, att.AttackSpeed) --> 51 66 105
att.Agility = 25;
print(att.Defence, att.MovementSpeed, att.AttackSpeed) --> 26 41 55
well i want to see all the attributes i have in the output.
Actually nevermind, your methods works perfectly, thanks you so much dude, i rly appreciate it.
Would be even cooler if you leave more info about proxies and etc.