Mysterious Entity:Fire Errors

I seem to get these errors on map load, even though it says Fire is nil it still functions as if normal.

Timer Error: autorun/door.lua:46: attempt to call method ‘Fire’ (a nil value)
[lua]
local function SetClosedDoors()
timer.Create( “SetClosedDelay”, 1, 1, function()
for k, v in pairs( ClosedDoors ) do
if Entity( v ):IsValid() then
Entity( v ):SetNWInt( “Type”, 1 )
Entity( v ):Fire( “lock”, “”, 0 ) //Line 46
end
end
end )
end
[/lua]

Timer Error: autorun/door.lua:72: attempt to call method ‘Fire’ (a nil value)
[lua]
local function SetAdminDoors()
timer.Create( “SetAdminDelay”, 1, 1, function()
for k, v in pairs( AdminDoors ) do
if Entity( v ):IsValid() then
Entity( v ):SetNWInt( “Type”, 3 )
Entity( v ):Fire( “lock”, “”, 0 ) //Line 72
Entity( v ):SetNWInt( “Locked”, 1 )
end
end
end )
end
[/lua]

I get this error only on the first call of this function.

Hook ‘UnlockDoors’ Failed: autorun/door.lua:92: attempt to call method ‘Fire’ (a nil value)
[lua]
local function UnlockDoors( ply, key )
local trace = ply:GetEyeTrace()

if trace.Entity:IsValid() then
	if key == IN_RELOAD and trace.Entity:IsDoor() then	
		if ply:IsAdmin() and trace.Entity:GetNWInt( "Type" ) == 3 and trace.Entity:GetNWInt( "Locked" ) == 1  then
			trace.Entity:Fire( "unlock", "", 0 ) //Line 92
			trace.Entity:Fire( "open", "", 0 )
			trace.Entity:SetNWInt( "Locked", 0 )
		elseif ply:IsAdmin() and trace.Entity:GetNWInt( "Type" ) == 3 and trace.Entity:GetNWInt( "Locked" ) == 0  then
			trace.Entity:Fire( "close", "", 0 )
			trace.Entity:Fire( "lock", "", 0 )
			trace.Entity:SetNWInt( "Locked", 1 )
		end
	end
end

end
hook.Add( “KeyPress”, “UnlockDoors”, UnlockDoors )
[/lua]

Even though these still function, I would like the error to die :smiley:

You don’t need Entity(v), just use v. Don’t know about the last one, though.

The v is a number, which is the entities index.

Err, the entity index will change…

I have been using entindex for three days now and the index has never changed.

Even still, I’m pretty sure Gb is right and that’s not a very stable way to code. Instead, I would refer to entities built into the map by target names (assuming you set them in hammer).

I was going for a system that I could apply to any map, it seems to work perfectly just shows some errors that seem to do nothing.

You can use **[Gamemode.EntityKeyValue

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Gamemode.EntityKeyValue)** to grab the targetname.

Is there not another way to target a specific generic door with no properties in hammer? The only way I could find was with index.

If they are spawned with the map then their ent index should never change, so it should be fine.