I googled for it, searched on facepunch and but i couldn’t find anything… There is some way to create an interrupts, just like in C? I need something like that because its pointless to make whole code execute (for example) 100 times per second, if i need only to make few lines so fast. And that take more CPU than interrupt i think…

Thanks in advance :slight_smile:

Why not do something like this in think:


if lastrun - CurTime() < 0.1 then
//Do your code here?
lastrun = CurTime()


Wouldn’t work because lastrun - CurTime() would always be 1/60

[lua]if CurTime() > nextrun then
– code
nextrun = CurTime() + 0.1;

You do the exact same thing only in a different way? I mean either way you are checking if 0.1 gametime passed?

For now I put that in think:

[lua]self.Entity:NextThink( CurTime() + 0.01 );
return true[/lua]

And i though about some function that is called independent of think, for example 100 times per second, when think is called with normal speed. And u can set in initialise, delays between each interrupt.

So there is no other way, but just use some global counter:
[lua]if(counter == 10) then //code
counter = 0;[/lua]


What exactly are you trying to do? Run part of a function 100 times a second but the rest at a slower rate?

I am working on a timer module which runs at max 100 times per second if that’s what you need. It calls a specified callback function every 0.01 seconds.

It doesn’t have to be global.
[lua]local NextThink = 0
function GM:Think()
if NextThink < CurTime() then
NextThink = CurTime() + 0.1

local ct = CurTime()
local Delay = 15
fucntion IliekTehCawkz()
if ( ct + Delay <= CurTime() ) then
print( “You sure liekz teh cawkz”)
ct = CurTime()

Troll much?

Kogitsune, yes, its exactly what I want.

Hmm, i just noticed that maybe I can use ENT.PhysicsSimulate for that, because i want turn something smothly.

Don’t take my avatar too serious. I actually got some knowledge of lohah.

It’s pretty much the only way to do it by timing it like that.


Actually, if you want to rotate something smoothly, look into rotating it and scaling how much, or using ShadowControl for the angles. Second one has examples on the wiki, but here’s how to rotate stuff:

function ENT:Think( )
  local a = self:GetAngles( )
  a:RotateAroundAxis( self:GetUp( ), 90 * FrameTime( ) )
  self:SetAngles( a )

Should make the entity rotate around it’s yaw, 90 degress per second, unless I messed it up.