Call: Difference between revisions
(Doc'd. Perhaps add a scoreboard doc to "See Also" in future.) |
(Fixed syntax, minor changes) |
||
Line 10: | Line 10: | ||
<script src="scoreboard_http.lua" type="server"/> | <script src="scoreboard_http.lua" type="server"/> | ||
<export function="getScoreboardColumns" http="true" /> | |||
<export function="getScoreboardRows" http="true" /> | <export function="getScoreboardRows" http="true" /> | ||
Line 22: | Line 22: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
var... call ( resource theResource, string theFunction, [ arguments... ] ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''theResource:''' This is a resource pointer which refers to the resource you are calling a function from. | *'''theResource:''' This is a resource pointer which refers to the resource you are calling a function from. | ||
*'''theFunction:''' This is a string of the function | *'''theFunction:''' This is a string with the name of the function which you want to call. | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
Line 37: | Line 35: | ||
===Returns=== | ===Returns=== | ||
Returns anything that the designated function has returned appropriately. If the function does not exist, is not exported, or the call was not successful it will return ''nil''. | |||
==Example== | ==Example== | ||
This extract shows adding of a "kills" column to the scoreboard resource. This then sets the ''gameShowKills'' variable to true, telling the rest of the script to start outputting kills. | |||
This extract shows adding of a " | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function showKills ( option ) | function showKills ( option ) | ||
if | if option == false then --if the option was set to false to turn it off | ||
--Its on, lets turn it off | --Its on, lets turn it off | ||
gameShowKills = false | gameShowKills = false | ||
call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "kills") | call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "kills") | ||
elseif option == true then | |||
--Its off, turn it on | --Its off, turn it on | ||
gameShowKills = true | gameShowKills = true |
Revision as of 11:17, 16 July 2007
This function is used to call a function from another resource.
The function which you wish to call must first be exported within the resource's meta. For example:
<meta> <info author="jbeta" type="script" description="Scoreboard resource" /> <script src="scoreboard_client.lua" type="client"/> <script src="scoreboard_exports.lua" type="server"/> <script src="scoreboard_http.lua" type="server"/> <export function="getScoreboardColumns" http="true" /> <export function="getScoreboardRows" http="true" /> <export function="addScoreboardColumn" type="server"/> <export function="removeScoreboardColumn" type="server"/> <export function="setPlayerScoreboardForced" type="server"/> <export function="setScoreboardForced" type="client"/> </meta>
This enables other resources to call a function from this resource.
Syntax
var... call ( resource theResource, string theFunction, [ arguments... ] )
Required Arguments
- theResource: This is a resource pointer which refers to the resource you are calling a function from.
- theFunction: This is a string with the name of the function which you want to call.
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- arguments: Any arguments you may want to pass to the function when it is called. Any number of arguments of can be specified, each being passed to the designated function.
Returns
Returns anything that the designated function has returned appropriately. If the function does not exist, is not exported, or the call was not successful it will return nil.
Example
This extract shows adding of a "kills" column to the scoreboard resource. This then sets the gameShowKills variable to true, telling the rest of the script to start outputting kills.
function showKills ( option ) if option == false then --if the option was set to false to turn it off --Its on, lets turn it off gameShowKills = false call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "kills") elseif option == true then --Its off, turn it on gameShowKills = true call(getResourceFromName("scoreboard"), "addScoreboardColumn", "kills") outputDebugString ( "Showing kills now..." ) end end
See Also
- abortRemoteRequest
- call
- fetchRemote
- getResourceConfig
- getResourceDynamicElementRoot
- getResourceExportedFunctions
- getResourceFromName
- getResourceName
- getResourceRootElement
- getResourceState
- getThisResource
- getRemoteRequests
- getRemoteRequestInfo