Difference between revisions of "WML for Complete Beginners: Chapter 8"

From The Battle for Wesnoth Wiki
(Created page with '==Chapter 8: Array, and Container Variables== So far we have only discussed ''scalar variables'', i.e. variables that have only one value at any given time. Believe it or not, t…')
 
(Nicer index and navigation)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{Translations}}<div style="float:right">{{:WML for Complete Beginners}}</div>
 +
 
==Chapter 8: Array, and Container Variables==
 
==Chapter 8: Array, and Container Variables==
  
 
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.
 
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.
 +
 +
 +
===Container Variables===
 +
 +
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!
 +
 +
Container variables are not restricted to containing scalar variables, however. They can also store other containers or even array variables.
  
 
===Array Variables===
 
===Array Variables===
  
 +
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.
  
  
===Container Variables===
+
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.
  
Container variables are variables that contain other variables within themselves. Returning to the metaphor of boxes, let's say you had three small boxes, labeled "Apples", "Oranges", and "Pears", respectively. Instead of having to carry around three smaller boxes, wouldn't it be much easier if we could just put them all in one large box labeled "fruit"? Well, with container variables, you can!
+
{{Navigation|[[WML for Complete Beginners: Chapter 7|'''Chapter 7'''<br>Variables Introduction]]|[[WML for Complete Beginners: Chapter 9|'''Chapter 9'''<br>Macros]]}}
  
Container variables are not restricted to containing scalar variables, however. They can also store array variables.
+
[[Category:WML_for_Complete_Beginners]]

Latest revision as of 19:20, 29 January 2023

Chapter 8: Array, and Container Variables

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.


Container Variables

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!

Container variables are not restricted to containing scalar variables, however. They can also store other containers or even array variables.

Array Variables

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.


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.

Navigation
Chapter 7
Variables Introduction
WML for Complete Beginners: Chapter 8 Chapter 9
Macros
This page was last edited on 29 January 2023, at 19:20.