Entity/AddCallback

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(moved this info to Entity Callbacks)
(GetCallbacks and RemoveCallbacks next update)
Line 3: Line 3:
  
 
This also allows you to use certain hooks in engine entities (non-scripted entities).
 
This also allows you to use certain hooks in engine entities (non-scripted entities).
 
{{Warning|Currently there is no way to remove or retrieve the callbacks of an entity.}}
 
  
 
{{Warning|This method does not check if the function has already been added to this object before, so if you add the same callback twice, it will be run twice! Make sure to add your callback only once.}}
 
{{Warning|This method does not check if the function has already been added to this object before, so if you add the same callback twice, it will be run twice! Make sure to add your callback only once.}}
 +
 +
{{NextUpdate|{{ClassFunction|Entity|GetCallbacks}} and {{ClassFunction|Entity|RemoveCallback}} will be added in an upcoming update}}
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=Yes
 
|IsClass=Yes

Revision as of 13:24, 20 June 2017

 Entity:AddCallback( )

Contents

Description

Add a callback function to a specific event. This is used instead of hooks to avoid calling empty functions unnecessarily.

This also allows you to use certain hooks in engine entities (non-scripted entities).

WARNING

This method does not check if the function has already been added to this object before, so if you add the same callback twice, it will be run twice! Make sure to add your callback only once.


Next Update Change

Entity:GetCallbacks and Entity:RemoveCallback will be added in an upcoming update

Arguments

string hook

The hook name to hook onto. See Entity Callbacks

Arguments

function func

The function to call

Returns

number

The callback ID that was just added, returns nothing if the passed callback function was invalid or when asking for a non-existent hook.

Examples

Example

function myfunc( entity, newangle )
	-- Do stuff
end

myentity:AddCallback( "OnAngleChange", myfunc )

Output:

Function is called every time the entity angle changes
Personal tools
Navigation