GetMapName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server function}}<!-- Change this to "Client function" or "Server function" appropriately--> <!-- Describe in plain english what this function does. Don't go into details, jus...)
 
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}<!-- Change this to "Client function" or "Server function" appropriately-->
{{Server function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function retrieves the current mapname as set by [[setMapName]].
This function retrieves the current mapname as set by [[setMapName]].


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string getMapName ()
string getMapName ()
Line 11: Line 9:


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns the mapname as a string. If no mapname is set it returns ''nil''.
Returns the mapname as a string. If no mapname is set it returns ''nil''.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example adds a ''checkmap'' command with which you can check what map you are currently playing.
This example does...
<!-- 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">
--TODO
function checkMap ( thePlayer )
    local mapName = getMapName() -- get the maps name
if mapName and mapName ~= "None" then -- if map name was set and it isn't "None" (default map name)
        outputChatBox( "You're playing map called \"" .. mapName .. "\"", thePlayer ) -- print out the map name
    else -- there was no name so tell that to player
        outputChatBox( "You're playing an unnamed map.", thePlayer ) -- print out the message
    end
end
addCommandHandler ( "checkmap", checkMap )
</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 -->
{{ASE functions}}
{{ASE functions}}
[[Category:Needs_Example]] <!-- leave this until the example is completed. -->

Revision as of 11:33, 4 April 2008

This function retrieves the current mapname as set by setMapName.

Syntax

string getMapName ()

Returns

Returns the mapname as a string. If no mapname is set it returns nil.

Example

This example adds a checkmap command with which you can check what map you are currently playing.

function checkMap ( thePlayer )
    local mapName = getMapName() -- get the maps name
	if mapName and mapName ~= "None" then -- if map name was set and it isn't "None" (default map name)
        outputChatBox( "You're playing map called \"" .. mapName .. "\"", thePlayer ) -- print out the map name
    else -- there was no name so tell that to player
        outputChatBox( "You're playing an unnamed map.", thePlayer ) -- print out the message
    end
end
addCommandHandler ( "checkmap", checkMap )

See Also

Template:ASE functions