Call: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Doc'd. Perhaps add a scoreboard doc to "See Also" in future.)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function is used to call a function from another resource.
This fake function is for use with blah & blah and does blahblahblabhalbhl
 
The function which you wish to call '''must''' first be exported within the resource's meta.  For example:
<syntaxhighlight lang="xml"><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></syntaxhighlight>
This enables other resources to call a function from this resource.


==Syntax==  
==Syntax==  
Line 10: Line 28:


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''theResource:''' This is a resource pointer which refers to the resource you are calling a function from.
*'''argumentName:''' description
*'''theFunction:''' This is a string of the function name which you want to call.


<!-- Only include this section below if there are optional arguments -->
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
*'''argumentName2:''' description
*'''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.
*'''argumentName3:''' description


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if blah, ''false'' otherwise.
Call will return anything that the designated function will return appropriately.  If the function does not exist, or was not successful it will return nil.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
<!-- Explain what the example is in a single sentance -->
This example does...
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.
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
function showKills ( option )
blabhalbalhb --abababa
if not ( option ) then --if the option was set to false to turn it off
--This line does this...
--Its on, lets turn it off
mooo
gameShowKills = false
call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "kills")
else
--Its off, turn it on
gameShowKills = true
call(getResourceFromName("scoreboard"), "addScoreboardColumn", "kills")
outputDebugString ( "Showing kills now..." )
end
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Resource_functions}}
{{FunctionArea_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function

Revision as of 20:38, 15 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

bool 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 of the function name 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

Call will return anything that the designated function will return appropriately. If the function does not exist, or 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 not ( option ) 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")
	else
		--Its off, turn it on
		gameShowKills = true
		call(getResourceFromName("scoreboard"), "addScoreboardColumn", "kills")
		outputDebugString ( "Showing kills now..." )
	end
end

See Also