<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://en.wiki.ryzom.com/w/index.php?action=history&amp;feed=atom&amp;title=Help%3AVariables</id>
		<title>Help:Variables - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://en.wiki.ryzom.com/w/index.php?action=history&amp;feed=atom&amp;title=Help%3AVariables"/>
		<link rel="alternate" type="text/html" href="https://en.wiki.ryzom.com/w/index.php?title=Help:Variables&amp;action=history"/>
		<updated>2026-05-27T05:23:46Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.1</generator>

	<entry>
		<id>https://en.wiki.ryzom.com/w/index.php?title=Help:Variables&amp;diff=4505&amp;oldid=prev</id>
		<title>CeNobiteElf: Created page with ''''Variables''' is a very simple MediaWiki extension that allows you to define a variable on a page, use it later in that same page, change its value, possibly to a value given b…'</title>
		<link rel="alternate" type="text/html" href="https://en.wiki.ryzom.com/w/index.php?title=Help:Variables&amp;diff=4505&amp;oldid=prev"/>
				<updated>2009-10-16T08:58:41Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;&amp;#039;&amp;#039;&amp;#039;Variables&amp;#039;&amp;#039;&amp;#039; is a very simple MediaWiki extension that allows you to define a variable on a page, use it later in that same page, change its value, possibly to a value given b…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;'''Variables''' is a very simple MediaWiki extension that allows you to define a variable on a page, use it later in that same page, change its value, possibly to a value given by an expression in terms of the old value, etc.&lt;br /&gt;
&lt;br /&gt;
It's much like a template, only very lightweight and scoped to only a single page, so you can use many variables on a page without polluting the wiki with huge numbers of templates. Combine with the [[ParserFunctions]] extension for best results.&lt;br /&gt;
&lt;br /&gt;
== Assigning a value to a variable ==&lt;br /&gt;
&lt;br /&gt;
=== #vardefine ===&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#vardefine:&amp;lt;/nowiki&amp;gt;''variablename''|''specifiedvalue''}}&lt;br /&gt;
&lt;br /&gt;
assigns the value ''specifiedvalue'' to the (already existing or hereby introduced) variable ''variablename''.&lt;br /&gt;
&lt;br /&gt;
=== #vardefineecho ===&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#vardefineecho:&amp;lt;/nowiki&amp;gt;''variablename''|''specifiedvalue''}}&lt;br /&gt;
&lt;br /&gt;
works exactly as &amp;lt;tt&amp;gt;#vardefine&amp;lt;/tt&amp;gt;, but the affected value is printed.&lt;br /&gt;
&lt;br /&gt;
== Retrieving the value of a variable (#var) ==&lt;br /&gt;
&lt;br /&gt;
The value of the variable ''variablename'' is produced by&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#var:&amp;lt;/nowiki&amp;gt;''variablename''}}&lt;br /&gt;
&lt;br /&gt;
If undefined, this produces the empty string; it does not give an error message.&lt;br /&gt;
&lt;br /&gt;
It's possible to define a value for the case that the variable is undefined or void:&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#var:&amp;lt;/nowiki&amp;gt;''variablename'' &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;''defaultvalue''&amp;lt;nowiki&amp;gt;}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
This is equivalent to:&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#if:&amp;lt;/nowiki&amp;gt; &amp;lt;nowiki&amp;gt;{{#var&amp;lt;/nowiki&amp;gt;:''variablename''}} |&amp;lt;nowiki&amp;gt;{{#var&amp;lt;/nowiki&amp;gt;:''variablename''}} |''defaultvalue''}}&lt;br /&gt;
but it's much shorter and better arranged.&lt;br /&gt;
&lt;br /&gt;
The value can be used in parser functions, etc.&lt;br /&gt;
&lt;br /&gt;
== #varexists ==&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#varexists:&amp;lt;/nowiki&amp;gt;''variablename''}} returns ''1'' if the variable is already defined (also when the value is a void string). If the variable is not defined the return value is void.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
: ''Note that the [[Extension:ParserFunctions|ParserFunctions extension]] must also be installed to use #expr''&lt;br /&gt;
&lt;br /&gt;
Compute 2*a + b:&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#expr:2*{{#var:a}}+{{#var:b}}}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
Add one to n:&lt;br /&gt;
:&amp;lt;nowiki&amp;gt;{{#vardefine:n|{{#expr:{{#var:n}}+1}}}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variables and conditional parser functions ==&lt;br /&gt;
This section only applies to MediaWiki versions below 1.12.&lt;br /&gt;
&lt;br /&gt;
=== [[Extension:ParserFunctions|ParserFunctions]] ===&lt;br /&gt;
&lt;br /&gt;
It must be noted that everything in conditional parser functions such as #ifexpr gets executed (though only one result gets displayed), regardless of the condition, &lt;br /&gt;
see [[m:ParserFunctions#Code_execution]].  This applies also to #vardefine. Thus: &lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{#ifexpr:..|&lt;br /&gt;
    {{#vardefine:a|b}}|&lt;br /&gt;
    {{#vardefine:a|c}}&lt;br /&gt;
}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
first assigns b and then c (hence effectively just c) regardless of the condition, while &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{#vardefine:a | {{#ifexpr:..|b|c}} }}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
assigns only the applicable value.&lt;br /&gt;
&lt;br /&gt;
Similarly&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{#ifexpr:..| {{#vardefine:a|b}}|}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
assigns b regardless of the condition, while &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{#vardefine:a | {{#ifexpr:..|b|{{#var:a}} }} }}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
conditionally assigns value b to variable a (a dummy assignment of the value of a to a is done if the condition is not fulfilled).&lt;br /&gt;
&lt;br /&gt;
=== [[Extension:Control Structure Functions|Control Structure Functions]] ===&lt;br /&gt;
&lt;br /&gt;
Another way around the aforementioned limitation is to use the [[Extension:Control Structure Functions|Control Structure Functions]] extension, which allows one to delay the parsing of wiki markup through the use of [[Extension:Control Structure Functions#Character Escapes|character escape sequences]].  So, the first above example becomes this:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{#ifexpr:..|&lt;br /&gt;
    \o#vardefine:a\pb\c|&lt;br /&gt;
    \o#vardefine:a\pc\c&lt;br /&gt;
}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, the [[Extension:Character Escapes|Character Escapes]] extension can be used to automate the escape sequences:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{#ifexpr:..|&lt;br /&gt;
    &amp;lt;esc&amp;gt;{{#vardefine:a|b}}&amp;lt;/esc&amp;gt;|&lt;br /&gt;
    &amp;lt;esc&amp;gt;{{#vardefine:a|c}}&amp;lt;/esc&amp;gt;&lt;br /&gt;
}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [[Extension:Control Structure Functions|Control Structure Functions]] extension also has loop functions that support character escape sequences.  The wiki markup:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{ #vardefine: i | 0 }}{{&lt;br /&gt;
  #while: expr&lt;br /&gt;
  | &amp;lt;esc&amp;gt;{{ #var: i }} &amp;lt; 3&amp;lt;/esc&amp;gt;&lt;br /&gt;
  | &amp;lt;esc&amp;gt;&lt;br /&gt;
* {{ #var: i }}{{ #vardefine: i | {{ #expr: {{ #var: i }} + 1 }} }}&amp;lt;/esc&amp;gt;&lt;br /&gt;
}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
produces the following:&lt;br /&gt;
&lt;br /&gt;
* 0&lt;br /&gt;
* 1&lt;br /&gt;
* 2&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
For more info see the [http://www.mediawiki.org/wiki/Extension:VariablesExtension extension page].&lt;/div&gt;</summary>
		<author><name>CeNobiteElf</name></author>	</entry>

	</feed>