hook/Call

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
Line 10: Line 10:
 
|type=string
 
|type=string
 
|name=hookName
 
|name=hookName
|desc=The hook name.
+
|desc=The hook name
 
}}
 
}}
 
{{Arg
 
{{Arg
 
|type=table
 
|type=table
 
|name=gamemodeTable
 
|name=gamemodeTable
|desc=If the gamemode is specified, the gamemode hook will be called, otherwise not.
+
|desc=If the gamemode is specified, the gamemode hook will be called, otherwise not
 
}}
 
}}
 
{{Arg
 
{{Arg
|type=any
+
|type=vararg
 
|name=args
 
|name=args
|desc=The arguments to be passed to the functions.
+
|desc=The arguments to be passed to the functions
 
}}
 
}}
 
{{Ret
 
{{Ret
|type=number
+
|type=any
|desc=return data from hook's call
+
|desc=Return data from hook's call
 
}}
 
}}
 
{{Example
 
{{Example
Line 37: Line 37:
 
     print("Done!")
 
     print("Done!")
 
end
 
end
 
+
hook.Add( "DoneDoingSomething", "Does something else", DoSomethingElse )
hook.Add("DoneDoingSomething", "Does something else", DoSomethingElse)
+
  
 
DoSomething()
 
DoSomething()
 
|Output=Done!
 
|Output=Done!
 
}}
 
}}

Revision as of 15:25, 24 January 2014

 hook.Call( )

Contents

Description

Calls hooks associated with the hook name
Calls all hooks until one returns something other than nil then returns that data.

Arguments

string hookName

The hook name

Arguments

table gamemodeTable

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

Arguments

vararg args

The arguments to be passed to the functions

Returns

any

Return data from hook's call

Examples

Example

Runs function DoSomething, which eventually calls a hook "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