Entity Timer Issue

Of course I’m still having issues with entities. Instead of deleting the whole entity, I decided to parent it with another entity, and what I wanted to make was when a player walked into the entity, it would simply move across the map and then come back after about a minute. ( Run-on’s FTW )

But I’m getting even more NIL errors now. I’m also don’t know which entity hook I should use for this. Creating my own function results in a NIL error on the entity, or setpos.

What I have

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

local self = {}

function ENT:Initialize( )
self:SetModel( “models/props_junk/sawblade001a.mdl” )
self:SetMoveType( MOVETYPE_NONE )
self:SetSolid( SOLID_VPHYSICS )
self:SetColor(0, 0, 0, 0)
end

function ENT:Touch( hitEnt )
if ( hitEnt:IsValid() and hitEnt:IsPlayer() ) then
self:SetPos( Vector( 1055.367310, -62.643860, 95.031250))
timer.Simple( 5, MoveBack)
timer.Simple( 5, Powerup )
end
end

function Powerup()
print(“Ugh… new test?”)
end

function MoveBack()
self:SetPos( Vector( 1019.322815, 439.279907, 65.031250 ) )
end

[/lua]

The powerup works, but anything that deals with the entity just gives me a NIL error. What should I do?

The two functions Powerup and MoveBack are not part of your entity, put ENT: in front of the function names and then you can use self.

I’ve tried that before and when I do that, I get the error of:



Timer Error: attempt to call a nil value


Um, what.
in the timers do;
[lua]
timer.Simple( 5, MoveBack() )
timer.Simple( 5, Powerup() )
[/lua]

I tried that before, and I get a new error D:



attempt to call global 'MoveBack' (a nil value)


All of this code is in the entity.

Why are you calling a function, when its not even made yet? ( i may be wrong ) but i don’t think your post to do that. You should put MoveBack and Powerup between touch and initialize

(the function)

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

local self = {}

function ENT:Initialize( )
self:SetModel( “models/props_junk/sawblade001a.mdl” )
self:SetMoveType( MOVETYPE_NONE )
self:SetSolid( SOLID_VPHYSICS )
self:SetColor(0, 0, 0, 0)
end

function ENT:Touch( hitEnt )
if ( hitEnt:IsValid() and hitEnt:IsPlayer() ) then
self:SetPos( Vector( 1055.367310, -62.643860, 95.031250))
timer.Simple( 5, self:MoveBack())
timer.Simple( 5, self:Powerup() )
end
end

function ENT:Powerup()
print(“Ugh… new test?”)
end

function ENT:MoveBack()
self:SetPos( Vector( 1019.322815, 439.279907, 65.031250 ) )
end

[/lua]

That still gives me a nil time error & now it wont even teleport.
The Powerup still works though.



Timer Error: attempt to call a nil value


Personally I use this for timers because timers never seem to work right for me.

[lua]

local Time = CurTime() + 120 --Two minutes

if (CurTime() > Time) then
–Do Stuff
end
[/lua]

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )

include( ‘shared.lua’ )

local self = {}

function ENT:Initialize( )
self:SetModel( “models/props_junk/sawblade001a.mdl” )
self:SetMoveType( MOVETYPE_NONE )
self:SetSolid( SOLID_VPHYSICS )
self:SetColor(0, 0, 0, 0)
end

function ENT:Powerup()
print(“Ugh… new test?”)
end

function ENT:MoveBack()
self:SetPos( Vector( 1019.322815, 439.279907, 65.031250 ) )
end

function ENT:Touch( hitEnt )
if ( hitEnt:IsValid() and hitEnt:IsPlayer() ) then
self:SetPos( Vector( 1055.367310, -62.643860, 95.031250))
timer.Simple( 5, function() self:MoveBack() self:Powerup() end)
end
end
[/lua]

Thank you so much. That was pretty complicated for something simple.