• Entity-specific timers?
    3 replies, posted
Is there a way to create entity specific timers? Whenever I create a timer within my SEnt script, it won't call a function like self:DoSomething() because it isn't part of the entity, and I also believe the timer itself won't be unique, so that if another identical entity does timer.Create(...) with the same identifier it will reset the progress. Is there anyway around this?
Simple timers are unique but they only run once [url]https://wiki.garrysmod.com/page/timer/Simple[/url] or create a regular timer with a unique name pertaining to the entity itself? timer.Create( "UniqueName1"..Self, 1, 1, function() end ) ? Not sure exactly what you are asking though
For identifier, "my string" .. ent:EntIndex(), for methods, use function() if !IsValid( ent ) then return end ent:DoSomething() end Where ent is your entity object.
[QUOTE=kulcris;50544297]Simple timers are unique but they only run once [url]https://wiki.garrysmod.com/page/timer/Simple[/url] or create a regular timer with a unique name pertaining to the entity itself? timer.Create( "UniqueName1"..Self, 1, 1, function() end )? Not sure exactly what you are asking though[/QUOTE] Running once is fine, but if you put them in your entity's code like in ENT:Initialize() and for the timer you do timer.Simple(10, self:DoSomething()) it will say the function DoSomething() is a nil value, and the same thing if for the function arg you do function() self:DoSomething() end EDIT: Well, I tested it with simple timer and the self functions work, but only if you do function() self:DoSomething() end
Sorry, you need to Log In to post a reply to this thread.