Entity/NextThink

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=NextThink
+
|Description=In the case of a scripted entity, this will cause the next {{HookFunction|ENTITY|Think}} event to be run at the given time.
|Parent=Entity
+
|Description=In the case of a scripted entity, this will cause the entity's next "OnThink" event to be run at the given time.
+
  
Does not work clientside!
+
Does not work clientside! Use {{ClassFunction|Entity|SetNextClientThink}} instead.
 +
 
 +
{{Bug|Issue=3269|This does not work with SWEPs or Nextbots.}}
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=Yes
 
|IsClass=Yes
Line 11: Line 11:
 
|type=number
 
|type=number
 
|name=timestamp
 
|name=timestamp
|desc=The timestamp at which the next think should occur.
+
|desc=The relative to {{GlobalFunction|CurTime}} timestamp, at which the next think should occur.
 
}}
 
}}
 
{{Example
 
{{Example
Line 18: Line 18:
 
     print("Hello, World!")
 
     print("Hello, World!")
  
     self:NextThink(CurTime() + 1)
+
     self:NextThink( CurTime() + 1 )
 
     return true -- Note: You need to return true to override the default next think time
 
     return true -- Note: You need to return true to override the default next think time
 
end
 
end
|Output=Hello, World!
+
|Output=Hello, World! every second the entity exists in the world.
 
}}
 
}}

Latest revision as of 15:45, 20 August 2019

 Entity:NextThink( )

Contents

Description

In the case of a scripted entity, this will cause the next ENTITY:Think event to be run at the given time.

Does not work clientside! Use Entity:SetNextClientThink instead.

BUG

This does not work with SWEPs or Nextbots.

Issue Tracker: #3269

Arguments

number timestamp

The relative to CurTime timestamp, at which the next think should occur.

Examples

Example

Prints 'Hello, World!' in console and sleeps for a second.

function ENT:Think()
    print("Hello, World!")

    self:NextThink( CurTime() + 1 )
    return true -- Note: You need to return true to override the default next think time
end

Output:

Hello, World! every second the entity exists in the world.
Personal tools
Navigation