hook/Call

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
Line 20: Line 20:
 
|type=vararg
 
|type=vararg
 
|name=args
 
|name=args
|desc=The arguments to be passed to the functions
+
|desc=The arguments to be passed to the hooks
 
}}
 
}}
 
{{Ret
 
{{Ret
 
|type=any
 
|type=any
|desc=Return data from hook's call
+
|desc=Return data from called hooks
 
}}
 
}}
 
{{Example
 
{{Example

Revision as of 18:39, 23 February 2014

 hook.Call( )

Contents

Description

Calls hooks associated with the given event
Calls all hooks until one returns something other than nil and then returns that data.

Arguments

string eventName

The event to call hooks for

Arguments

table gamemodeTable

If the gamemode is specified, the gamemode hook within will be called, otherwise not

Arguments

vararg args

The arguments to be passed to the hooks

Returns

any

Return data from called hooks

Examples

Example

Runs function DoSomething, which eventually calls the event "DoneDoingSomething", triggering the hooked function DoSomethingElse.

function DoSomething()
    --Does something
    hook.Call("DoneDoingSomething")
end

function DoSomethingElse()
    --Does something else, once the hook DoneDoingSomething is called.
    print("Done!")
end
hook.Add( "DoneDoingSomething", "Does something else", DoSomethingElse )

DoSomething()

Output:

Done!
Personal tools
Navigation