Hello,
i try to get a keyvalue from an entity spawned on the map start.
When the map start :
two entity spawn close to each other ( A and B )
but i want to retrieve the first entity keyvalue in a short distance from the second..
keyvalue exist etc.. but the code is wrong i'm sure..
here the code :
first entity that need to retrieve the keyvalue :
function ENT:Initialize()
for k, v in pairs( ents.FindByClass( "my_entity" ) ) do
if v:IsValid() and self:GetPos():Distance( v:GetPos() ) <= 120 then
local value = tostring(v:GetKeyValues().myvalue)
print(value) -- print nil to the console because, it don't retrieve the value but the value exist on the entity i'm sure i have checked ( i think is the method to retrieve incorrect
if value then
self:SetKeyValue( "myvalue", value )
end
end
end
end
Keyvalues are set AFTER Initialize is called. You want to capture them in ENTITY/KeyValue
Sorry, you need to Log In to post a reply to this thread.