<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Uhmpr0</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Uhmpr0"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Uhmpr0"/>
	<updated>2026-04-10T06:17:47Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=IfElse&amp;diff=34470</id>
		<title>IfElse</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=IfElse&amp;diff=34470"/>
		<updated>2013-01-13T09:21:07Z</updated>

		<summary type="html">&lt;p&gt;Uhmpr0: adding these things so people can search for these words&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Useful Function}}&lt;br /&gt;
__NOTOC__&lt;br /&gt;
This function just adds a possibility to integrate a condition in e.g. some variable definition. It is as useful as simple. It's like the short “(c) ? t : f ;” statement that exists in e.g. PHP or JavaScript, or COALESCE in MySQL. It simulates a ternary operation.&lt;br /&gt;
&lt;br /&gt;
''Note: This function is basically on the wiki to enable using it in other useful functions.''&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;var IfElse( bool condition, var trueReturn, var falseReturn )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Required Arguments===&lt;br /&gt;
* '''condition''': A condition like you could use it in an if-statement.&lt;br /&gt;
* '''trueReturn''': The value that should be returned if the condition is true.&lt;br /&gt;
* '''falseReturn''': The value that should be returned if the condition is false.&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the second argument if condition is true, the third otherwise.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server- and/or clientside Script&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
function IfElse(condition, trueReturn, falseReturn)&lt;br /&gt;
    if (condition) then return trueReturn&lt;br /&gt;
    else return falseReturn end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;section name=&amp;quot;Server&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
This example adds a command to retrieve the actual player count.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- define the commandhandler function&lt;br /&gt;
function CmdPlayerCount(source)&lt;br /&gt;
    -- get the actual player count&lt;br /&gt;
    local playerCount = getPlayerCount()&lt;br /&gt;
    -- send message to the player&lt;br /&gt;
    outputChatBox(&amp;quot;There &amp;quot;..IfElse(playerCount == 1, &amp;quot;is&amp;quot;, &amp;quot;are&amp;quot;)..&amp;quot; actually &amp;quot;..playerCount..&amp;quot; Player&amp;quot;..IfElse(playerCount == 1, &amp;quot;&amp;quot;, &amp;quot;s&amp;quot;)..&amp;quot; online.&amp;quot;, source)&lt;br /&gt;
end&lt;br /&gt;
-- add the command handler&lt;br /&gt;
addCommandHandler(&amp;quot;playerCount&amp;quot;, CmdPlayerCount, false, false)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Author: NeonBlack&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Useful_Functions}}&lt;/div&gt;</summary>
		<author><name>Uhmpr0</name></author>
	</entry>
</feed>