<!DOCTYPE html>
<!-- saved from url=(0062)https://wiki.wesnoth.org/WML_for_Complete_Beginners:_Chapter_8 -->
<html class="client-js flexbox flexwrap" lang="en" dir="ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WML for Complete Beginners: Chapter 8 - The Battle for Wesnoth Wiki</title>
<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>
<script>(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"WML_for_Complete_Beginners:_Chapter_8","wgTitle":"WML for Complete Beginners: Chapter 8","wgCurRevisionId":58366,"wgRevisionId":58366,"wgArticleId":5683,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["WML for Complete Beginners"],"wgBreakFrames":false,"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgMonthNamesShort":["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"wgRelevantPageName":"WML_for_Complete_Beginners:_Chapter_8","wgRelevantArticleId":5683,"wgRequestId":"c7c40616743719d9a6697f0b","wgIsProbablyEditable":false,"wgRelevantPageIsProbablyEditable":false,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgWikiEditorEnabledModules":[]});mw.loader.state({"site.styles":"ready","noscript":"ready","user.styles":"ready","user":"ready","user.options":"ready","user.tokens":"loading","ext.CookieWarning.styles":"ready","mediawiki.legacy.shared":"ready","mediawiki.legacy.commonPrint":"ready","mediawiki.sectionAnchor":"ready"});mw.loader.implement("user.tokens@15m2fsb",function($,jQuery,require,module){/*@nomin*/mw.user.tokens.set({"editToken":"+\\","patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"});
});mw.loader.load(["site","mediawiki.page.startup","mediawiki.user","mediawiki.hidpi","mediawiki.page.ready","mediawiki.searchSuggest","ext.CookieWarning","skins.wesmere.js"]);});</script>
<link rel="stylesheet" href="./WML for Complete Beginners_ Chapter 8 - The Battle for Wesnoth Wiki_files/load.php">
<script async="" src="./WML for Complete Beginners_ Chapter 8 - The Battle for Wesnoth Wiki_files/load(1).php"></script>
<style>
.suggestions{overflow:hidden;position:absolute;top:0;left:0;width:0;border:0;z-index:1099;padding:0;margin:-1px 0 0 0}.suggestions-special{position:relative;background-color:#fff;cursor:pointer;border:1px solid #a2a9b1;margin:0;margin-top:-2px;display:none;padding:0.25em 0.25em;line-height:1.25em}.suggestions-results{background-color:#fff;cursor:pointer;border:1px solid #a2a9b1;padding:0;margin:0}.suggestions-result{color:#000;margin:0;line-height:1.5em;padding:0.01em 0.25em;text-align:left; overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.suggestions-result-current{background-color:#2a4b8d;color:#fff}.suggestions-special .special-label{color:#72777d;text-align:left}.suggestions-special .special-query{color:#000;font-style:italic;text-align:left}.suggestions-special .special-hover{background-color:#c8ccd1}.suggestions-result-current .special-label,.suggestions-result-current .special-query{color:#fff}.highlight{font-weight:bold}</style><style>
.suggestions a.mw-searchSuggest-link,.suggestions a.mw-searchSuggest-link:hover,.suggestions a.mw-searchSuggest-link:active,.suggestions a.mw-searchSuggest-link:focus{color:#000;text-decoration:none}.suggestions-result-current a.mw-searchSuggest-link,.suggestions-result-current a.mw-searchSuggest-link:hover,.suggestions-result-current a.mw-searchSuggest-link:active,.suggestions-result-current a.mw-searchSuggest-link:focus{color:#fff}.suggestions a.mw-searchSuggest-link .special-query{ overflow:hidden;text-overflow:ellipsis;white-space:nowrap}</style><meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="./WML for Complete Beginners_ Chapter 8 - The Battle for Wesnoth Wiki_files/load(2).php">
<meta name="generator" content="MediaWiki 1.31.16">
<meta name="description" content="So far we have only discussed scalar variables, i.e. variables that have only one value at any given time. Believe it or not, there are types of variables than can store more than one value simultaneously, or even other variables.">
<link rel="shortcut icon" href="https://wiki.wesnoth.org/favicon.ico">
<link rel="search" type="application/opensearchdescription+xml" href="https://wiki.wesnoth.org/opensearch_desc.php" title="The Battle for Wesnoth Wiki (en)">
<link rel="EditURI" type="application/rsd+xml" href="https://wiki.wesnoth.org/api.php?action=rsd">
<link rel="alternate" type="application/atom+xml" title="The Battle for Wesnoth Wiki Atom feed" href="https://wiki.wesnoth.org/index.php?title=Special:RecentChanges&feed=atom">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="./WML for Complete Beginners_ Chapter 8 - The Battle for Wesnoth Wiki_files/css" type="text/css">
<link rel="stylesheet" type="text/css" href="./WML for Complete Beginners_ Chapter 8 - The Battle for Wesnoth Wiki_files/wesmere-1.1.9.css">
<script src="./WML for Complete Beginners_ Chapter 8 - The Battle for Wesnoth Wiki_files/modernizr.js"></script><script src="./WML for Complete Beginners_ Chapter 8 - The Battle for Wesnoth Wiki_files/load(3).php"></script>
<link rel="apple-touch-icon" type="image/png" href="https://www.wesnoth.org/wesmere/img/apple-touch-icon.png" sizes="180x180">
<link rel="icon" type="image/png" href="https://www.wesnoth.org/wesmere/img/favicon-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="https://www.wesnoth.org/wesmere/img/favicon-16.png" sizes="16x16">
<!--[if lt IE 9]><script src="/load.php?debug=false&lang=en&modules=html5shiv&only=scripts&skin=Wesmere&sync=1"></script><![endif]-->
</head>
<body class="mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-WML_for_Complete_Beginners_Chapter_8 rootpage-WML_for_Complete_Beginners_Chapter_8 skin-Wesmere action-view"><div class="mw-cookiewarning-container"><div class="mw-cookiewarning-text"><span>Cookies help us deliver our services. By using our services, you agree to our use of cookies.</span><form method="POST"><input name="disablecookiewarning" class="mw-cookiewarning-dismiss" type="submit" value="OK"></form></div></div>
<div id="main">
<div id="nav" role="banner">
<div class="centerbox">
<div id="logo">
<a href="https://www.wesnoth.org/" aria-label="Wesnoth logo"></a>
</div>
<ul id="navlinks">
<li><a href="https://www.wesnoth.org/">Home</a></li>
<li><a href="https://forums.wesnoth.org/viewforum.php?f=62">News</a></li>
<li><a href="https://wiki.wesnoth.org/Play">Play</a></li>
<li><a href="https://wiki.wesnoth.org/Create">Create</a></li>
<li><a href="https://forums.wesnoth.org/">Forums</a></li>
<li><a href="https://wiki.wesnoth.org/Project">About</a></li>
</ul>
<div id="sitesearch" role="search">
<form method="get" action="https://wiki.wesnoth.org/index.php">
<input id="searchbox" type="search" name="search" placeholder="Search" value="" title="Search this wiki [ctrl-option-f]" accesskey="f">
<span id="searchbox-controls">
<button id="search-go" class="search-button" type="submit" title="Search">
<i class="search-icon" aria-hidden="true"></i>
<span class="sr-label">Search this wiki</span>
</button>
</span>
</form>
</div>
<div class="reset"></div>
</div>
</div>
<div id="content" class="mw-content" role="main">
<a id="top"></a>
<div id="wm-wiki-toolbar" role="toolbar"><ul class="wm-toolbar" role="toolbar" aria-label="Wiki"><li id="ca-nstab-main" class="selected"><a href="https://wiki.wesnoth.org/WML_for_Complete_Beginners:_Chapter_8" role="button" title="View the content page [ctrl-option-c]" accesskey="c"><i class="wm-toolbar-icon" aria-hidden="true"></i><span class="sr-label">Page</span></a></li><li id="ca-talk" class="new"><a href="https://wiki.wesnoth.org/index.php?title=Talk:WML_for_Complete_Beginners:_Chapter_8&action=edit&redlink=1" rel="discussion" role="button" title="Discussion about the content page (page does not exist) [ctrl-option-t]" accesskey="t"><i class="wm-toolbar-icon" aria-hidden="true"></i><span class="sr-label">Discussion</span></a></li><li id="ca-history"><a href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_8&action=history" role="button" title="Past revisions of this page [ctrl-option-h]" accesskey="h"><i class="wm-toolbar-icon" aria-hidden="true"></i><span class="sr-label">History</span></a></li><li id="wm-places-menu" class="wm-dropdown"><a class="wm-dropdown-trigger" href="https://wiki.wesnoth.org/WML_for_Complete_Beginners:_Chapter_8#" title="Places" role="button"><i class="wm-toolbar-icon" aria-hidden="true"></i><span class="sr-label">Places</span><i class="wm-toolbar-dropdown-marker" aria-hidden="true"></i></a><ul class="wm-dropdown-menu" role="menu"><li id="n-mainpage-description"><a href="https://wiki.wesnoth.org/Main_Page" role="menuitem" title="Visit the main page [ctrl-option-z]" accesskey="z"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Main page</span></a></li><li id="n-recentchanges"><a href="https://wiki.wesnoth.org/Special:RecentChanges" role="menuitem" title="A list of recent changes in the wiki [ctrl-option-r]" accesskey="r"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Recent changes</span></a></li><li id="n-randompage"><a href="https://wiki.wesnoth.org/Special:Random" role="menuitem" title="Load a random page [ctrl-option-x]" accesskey="x"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Random page</span></a></li><li id="n-help-mediawiki"><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents" role="menuitem"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Help about MediaWiki</span></a></li></ul></li><li id="wm-advanced-menu" class="wm-dropdown"><a class="wm-dropdown-trigger" href="https://wiki.wesnoth.org/WML_for_Complete_Beginners:_Chapter_8#" title="Advanced" role="button"><i class="wm-toolbar-icon" aria-hidden="true"></i><span class="sr-label">Advanced</span><i class="wm-toolbar-dropdown-marker" aria-hidden="true"></i></a><ul class="wm-dropdown-menu" role="menu"><li id="ca-viewsource"><a href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_8&action=edit" role="menuitem" title="This page is protected.
You can view its source [ctrl-option-e]" accesskey="e"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>View source</span></a></li><li id="t-whatlinkshere"><a href="https://wiki.wesnoth.org/Special:WhatLinksHere/WML_for_Complete_Beginners:_Chapter_8" role="menuitem" title="A list of all wiki pages that link here [ctrl-option-j]" accesskey="j"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>What links here</span></a></li><li id="t-recentchangeslinked"><a href="https://wiki.wesnoth.org/Special:RecentChangesLinked/WML_for_Complete_Beginners:_Chapter_8" rel="nofollow" role="menuitem" title="Recent changes in pages linked from this page [ctrl-option-k]" accesskey="k"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Related changes</span></a></li><li id="t-specialpages"><a href="https://wiki.wesnoth.org/Special:SpecialPages" role="menuitem" title="A list of all special pages [ctrl-option-q]" accesskey="q"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Special pages</span></a></li><li id="t-permalink"><a href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_8&oldid=58366" role="menuitem" title="Permanent link to this revision of the page"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Permanent link</span></a></li><li id="t-info"><a href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_8&action=info" role="menuitem" title="More information about this page"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Page information</span></a></li></ul></li></ul><ul class="wm-toolbar" role="toolbar" aria-label="User"><li id="wm-account-menu" class="wm-dropdown"><a class="wm-dropdown-trigger" href="https://wiki.wesnoth.org/WML_for_Complete_Beginners:_Chapter_8#" title="Your account" role="button"><i class="wm-toolbar-icon" aria-hidden="true"></i><span class="sr-label">Not logged in</span><i class="wm-toolbar-dropdown-marker" aria-hidden="true"></i></a><ul class="wm-dropdown-menu" role="menu"><li id="pt-login"><a href="https://wiki.wesnoth.org/index.php?title=Special:UserLogin&returnto=WML+for+Complete+Beginners%3A+Chapter+8" role="menuitem" title="You are encouraged to log in; however, it is not mandatory [ctrl-option-o]" accesskey="o"><i class="wm-toolbar-icon" aria-hidden="true"></i><span>Log in</span></a></li></ul></li></ul></div> <!-- wm-wiki-toolbar --> <h1 class="firstHeading" lang="en">WML for Complete Beginners: Chapter 8</h1>
<div id="bodyContent">
<div id="siteSub">From The Battle for Wesnoth Wiki</div>
<div id="contentSub"></div>
<!-- start wikipage -->
<div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div class="mw-parser-output"><h2><span id="Chapter_8:_Array,_and_Container_Variables"></span><span class="mw-headline" id="Chapter_8:_Array.2C_and_Container_Variables">Chapter 8: Array, and Container Variables</span></h2>
<p>So far we have only discussed <i>scalar variables</i>, i.e. variables that have only one value at any given time. Believe it or not, there are types of variables than can store more than one value simultaneously, or even other variables.
</p><p><br>
</p>
<h3><span class="mw-headline" id="Container_Variables">Container Variables</span></h3>
<p>Container variables are variables that contain other variables within themselves. Just imagine how many variables you could create for information about one unit. There could be a variable my_leader_hitpoints, my_leader_name, my_leader_level, and so on. Instead of having all these different variables, wouldn't it be much easier if we could just put them all in one large box labeled "my_leader"? Well, with container variables, you can!
</p><p>Container variables are not restricted to containing scalar variables, however. They can also store other containers or even array variables.
</p>
<h3><span class="mw-headline" id="Array_Variables">Array Variables</span></h3>
<p>You will typically encounter Array variables when you need to store all the units or locations on the map that meet certain criteria. That is outside the scope of this beginner's tutorial, but later you can consult the ReferenceWML documentation for [store_unit] and [store_locations] when you are ready to do that.
</p><p><br>
Here are some basic facts about Array Variables. Every Array has a length, which is the number of its containers. And these containers are all numbered starting at container zero.
</p><p><br>
Next Chapter:
<a href="https://wiki.wesnoth.org/WML_for_Complete_Beginners:_Chapter_9" title="WML for Complete Beginners: Chapter 9">WML for Complete Beginners: Chapter 9</a>
</p><p>Previous Chapter:
<a href="https://wiki.wesnoth.org/WML_for_Complete_Beginners:_Chapter_7" title="WML for Complete Beginners: Chapter 7">WML for Complete Beginners: Chapter 7</a>
</p><p>Return to Main Index:
<a href="https://wiki.wesnoth.org/WML_for_Complete_Beginners" title="WML for Complete Beginners">WML for Complete Beginners</a>
</p>
<!--
NewPP limit report
Cached time: 20211208130606
Cache expiry: 86400
Dynamic content: false
CPU time usage: 0.002 seconds
Real time usage: 0.003 seconds
Preprocessor visited node count: 10/1000000
Preprocessor generated node count: 16/1000000
Post?expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Highest expansion depth: 2/40
Expensive parser function count: 0/100
Unstrip recursion depth: 0/20
Unstrip post?expand size: 0/5000000 bytes
-->
<!--
Transclusion expansion time report (%,ms,calls,template)
100.00% 0.000 1 -total
-->
</div>
<!-- Saved in parser cache with key wiki-mw_:pcache:idhash:5683-0!canonical and timestamp 20211208130606 and revision id 58366
-->
</div> <!-- end wikipage -->
<div class="printfooter">
Retrieved from "<a dir="ltr" href="https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_8&oldid=58366">https://wiki.wesnoth.org/index.php?title=WML_for_Complete_Beginners:_Chapter_8&oldid=58366</a>" </div>
<div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="https://wiki.wesnoth.org/Special:Categories" title="Special:Categories">Category</a>: <ul><li><a href="https://wiki.wesnoth.org/Category:WML_for_Complete_Beginners" title="Category:WML for Complete Beginners">WML for Complete Beginners</a></li></ul></div></div><div id="lastmod"> This page was last edited on 18 April 2017, at 03:14.</div> <div class="visualClear"></div>
</div> <!-- bodyContent -->
</div> <!-- end content -->
</div> <!-- end main -->
<div id="footer-sep"></div>
<div id="footer"><div id="footer-content"><div>
<a href="https://wiki.wesnoth.org/StartingPoints">Site Map</a> ? <a href="https://status.wesnoth.org/">Site Status</a><br>
Copyright © 2003?2021 by <a rel="author" href="https://wiki.wesnoth.org/Project">The Battle for Wesnoth Project</a>. Powered by <a href="https://www.mediawiki.org/">MediaWiki</a>.<br>
Site design Copyright © 2017?2021 by Iris Morelle.
</div></div></div>
<script>(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"0.002","walltime":"0.003","ppvisitednodes":{"value":10,"limit":1000000},"ppgeneratednodes":{"value":16,"limit":1000000},"postexpandincludesize":{"value":0,"limit":2097152},"templateargumentsize":{"value":0,"limit":2097152},"expansiondepth":{"value":2,"limit":40},"expensivefunctioncount":{"value":0,"limit":100},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":0,"limit":5000000},"timingprofile":["100.00% 0.000 1 -total"]},"cachereport":{"timestamp":"20211208130606","ttl":86400,"transientcontent":false}}});});</script><script>(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgBackendResponseTime":29});});</script></body></html>
|