Difference between revisions of "WML for Complete Beginners"

From The Battle for Wesnoth Wiki
(Add includeonly index link)
 
(84 intermediate revisions by 11 users not shown)
Line 1: Line 1:
'''Template for future "WML for Complete Beginners" tutorial'''
+
{{Translations}}
  
'''Note: this is a work in progress.'''
+
Welcome to the WML Guide for Complete Beginners!  From here, you can get started directly by heading to the [[WML for Complete Beginners: Introduction|Introduction]] or you can continue from the chapter you left off.
-------------
 
  
 +
==Main Index==
  
 
+
<onlyinclude>
 
+
{| class="wikitable"
==Introduction==
+
<includeonly>|-
 
+
|[[WML for Complete Beginners|Index]]</includeonly>
Hey there!
+
|-
 
+
|[[WML_for_Complete_Beginners:_Introduction|Introduction]]
Now I'm guessing that, if you're reading this, you already know what The Battle for Wesnoth is. If you don't, I suggest finding out before reading further.  If you have played...blahblahblah. (placeholder)
+
|-
 
+
|[[WML_for_Complete_Beginners:_Chapter_1|1 - Syntax]]
===Who This Tutorial is For===
+
|-
This tutorial is aimed at users with no previous programming knowledge. This tutorial does assume that you have a certain level of competence in basic computer skills and concepts, such as opening and editing text files, and being able to follow folder directories. In this tutorial you will learn WML by building a short single-player campaign from the ground up.
+
|[[WML_for_Complete_Beginners:_Chapter_2|2 - The Userdata Directory and the Campaign Folder]]
 
+
|-
===What Tools You Will Need===
+
|[[WML_for_Complete_Beginners:_Chapter_3|3 - The _main.cfg]]
 
+
|-
Programming WML requires only one tool: a basic text editor. You don't need a fancy word processor to program WML; a simple program like Windows Notepad or Mac OS X TextEdit will work just fine. For Linux, there is a very nice text editing application called Kate that actually comes with syntax highlighting for WML.
+
|[[WML_for_Complete_Beginners:_Chapter_4|4 - Creating Your First Scenario]]
 
+
|-
===So What Exactly is WML?===
+
|[[WML_for_Complete_Beginners:_Chapter_5|5 - Events]]
 
+
|-
WML is an acronym for the "Wesnoth Markup Language", a custom scripting language that The Battle For Wesnoth uses to allow players to create and modify content without having to learn a much more complex language like Lua or C++. Now I'm going to say this here and now: don't think you can learn WML overnight. Although WML is relatively easy to learn, it will take a certain amount of effort, time and dedication to fully understand the ins and outs of the language.
+
|[[WML_for_Complete_Beginners:_Chapter_6|6 - Custom Units]]
 
+
|-
==Chapter 1: Syntax==
+
|[[WML_for_Complete_Beginners:_Chapter_7|7 - Variables Introduction]]
 
+
|-
First things first; let's go over the ''syntax'' of WML.
+
|[[WML_for_Complete_Beginners:_Chapter_8|8 - Non-scalar Variables]]
 
+
|-
For those of you who might not know what the "syntax" of a language is, think of it as a set of rules for how WML needs to be written in order for the game to understand it. This concept may sound a bit confusing, but whether you realize it or not you have been using the concept of syntax your entire life! Think of the structure of a sentence in English: "I like jelly and cheese sandwiches." That sentence uses a certain set of rules, or ''syntax'' in order to make sense to people who hear or read it. If you said instead, "Like cheese I and sandwiches jelly", that would make no sense, and no one would understand what you were saying. Likewise, if you said "I like cheese sandwiches and jelly", that would change the entire meaning of the sentence!
+
|[[WML_for_Complete_Beginners:_Chapter_9|9 - Macros]]
 
 
Just like the syntax of the English language, WML syntax also requires proper capitalization, spelling, grammar and punctuation in order for others to understand what you're saying or writing. For example, if you decided to ignore the syntax of the English language and wrote something like this: "won day mary and i had went to seen the elefant at the zoo it's trunc was reely long", chances are people would not understand much of what you wrote. On the other hand, if you used the correct syntax and wrote: "One day Mary and I went to see the elephant at the zoo. Its trunk was really long!", people can easily understand what you wrote because it is written in the syntax they recognize and understand. Just as English-reading people would be unable to understand something were it not written in the correct English syntax, the Battle for Wesnoth game is unable to read any WML that is not written in the correct WML syntax.
 
 
 
So now let's go over the basics of WML syntax. Later on you will be gradually introduced to more complex WML syntax, but for now we'll just go over the basic stuff, enough to get you started.
 
 
 
===Basic Components: Tags and Attributes===
 
 
 
WML, as one can infer from the meaning of the acronym, is a [http://en.wikipedia.org/wiki/Markup_language markup language]. This means that the syntax of the entire language consists of two fundamental elements: tags and attributes.
 
 
 
====Tags====
 
A tag is a string of lowercase text encapsulated by two square brackets, one at either end. This is an example of a "campaign" tag:
 
[campaign]
 
 
 
Notice that I said "a tag is a string of ''lowercase'' text". This is a fundamental aspect of the WML syntax: all tags are always written in lowercase letters. If you try and use capital letters (even just one), the WML engine won't be able to understand what you've written and will give you an error when it tries to read the incorrect tag.
 
 
 
As with most markup languages, in WML tags are always used in pairs: one opening tag and one closing tag. Think of the opening tag and the closing tag like the covers of a book: when you open the front cover, you know you're at the beginning. When you reach the back cover, you know you're done reading the book. Likewise, when the WML engine finds an opening tag, it realizes it's at the beginning of a task. When it reaches the closing tag, it realizes it has finished the task.
 
 
 
Closing tags are exactly the same as opening tags except for one key component: closing tags always have a forward slash "/" immediately after the first square bracket. This forward slash tells the WML engine that this tag is a closing tag and not another opening tag. Here is an example of the closing "campaign" tag:
 
[/campaign]
 
 
 
The opening and closing tag together are referred to as a "tagset". A tagset always contains exactly two tags: the opening tag and the closing tag. So the "campaign" tagset would look like this:
 
[campaign]
 
[/campaign]
 
 
 
So now we know how the WML engine knows where the beginning and end of a task are, and what syntax to use when writing them. Before we move on to the next section, let's review the points we've learned in this section about tags:
 
*A tag is a string of lowercase text encapsulated by two square brackets, one at either end.
 
*A closing tag is exactly the same as an opening tag except for the forward slash immediately following the first square bracket.
 
*The opening tag and the closing tag together are called the tagset. A tagset consists of only two tags: the opening tag and the closing tag.
 
 
 
So now we know how to tell the WML engine where the beginning and the end of a task are, but what about actually making it do the task? This is where attributes come in.
 
 
 
====Attributes====
 
 
 
Attributes consist of two principal elements: ''keys'' and ''values''.
 
 
 
===More About Tags===
 
-Discuss nested tags, whitespaces and underscores in tags
 
 
 
 
 
==Chapter 2: The Userdata Directory and the Campaign Folder==
 
 
 
===The Userdata Directory===
 
 
 
There are two main directories that Wesnoth creates on your computer. The '''installation directory''' contains all the files for the core game. The '''userdata directory''' stores all your personal Wesnoth data, which includes your installed add-ons, your settings and preferences, and your saved games. This is where we will store your work throughout this tutorial.
 
 
 
The location of your userdata directory differs depending on your operating system, and in the case of Microsoft Windows, the version of your operating system. Refer to the following table to determine where your userdata directory is located.
 
 
 
 
 
{| border="1"
 
!Windows XP
 
|~/My Documents/My Games/Wesnoth 1.10/
 
 
|-
 
|-
!Windows Vista and above
+
|[[WML_for_Complete_Beginners:_Chapter_10|10 - Logic]]
|~/Documents/My Games/Wesnoth 1.10/
 
 
|-
 
|-
!Mac OS X
+
|[[WML_for_Complete_Beginners:_Chapter_11|11 - More Logic]]
|~/Library/Application Support/Wesnoth 1.10/
 
 
|-
 
|-
!Linux
+
|[[WML_for_Complete_Beginners:_Conclusion|Conclusion]]
|~/.local/share/wesnoth/1.10/
 
 
|}
 
|}
 +
</onlyinclude>
  
 +
==Note for Improvements:==
  
Now navigate to your userdata folder. You should see a total of five folders ("cache", "data", "editor", "persist", and "saves") in this directory, along with two files ("preferences" and "save_index.gz"). If you see all seven of these, everything is good. If you do not see all seven, try running the Wesnoth application. If that does not work, try restarting your computer. If neither of these steps work, reinstall Wesnoth.
+
1. Add to the numbers definition that numbers can include decimal point values (and reference the fact that WML will remove any unnecessary 0's when it performs the calculations or accesses the numerical value in question).
 
 
Of the seven objects contained in the userdata folder, you will only ever need to interact with two: the "data" folder and the "editor" folder.
 
 
 
====The data folder====
 
 
 
The data folder is where all installed add-ons are kept. This is where we will be building our campaign, when we get to that. If you have installed any Wesnoth add-ons, they should show up in this folder.
 
 
 
====The editor folder====
 
 
 
The editor folder is where all maps created with the in-game map editor are stored. If you have ever created and saved a map in-game, you should see the map file in this directory.
 
 
 
===The Campaign Folder===
 
 
 
Like I told you earlier, all add-ons are installed in the data folder inside the userdata directory. That means that your campaign will also be located inside the data folder. If you're not already there, enter the data folder now.
 
 
 
Next, create a new folder inside the data folder. Name this new folder "my_campaign" exactly as I wrote it here (but don't include the quotation marks). Make sure you spelled it right, that you didn't accidentally capitalize any letters and that you included the underscore between "my" and "campaign" in the folder name, or your campaign won't work when you try and play it.
 
 
 
Now enter the "my_campaign" folder and create six new folders. Name these folders "images", "macros", "maps", "scenarios", "units" and "utils" (again, make sure you spelled everything right, that you didn't accentually capitalize anything, and that you don't include the quotation marks).
 
 
 
All campaigns share this common folder structure.
 
 
 
==Chapter 3: The _main.cfg==
 
 
 
 
 
And now we're going to add the "campaign" tagset. Yes, it's our old friend "campaign" from Chapter 1. This
 
 
 
 
 
==Chapter 4: Creating Your First Scenario==
 
 
 
Now that you have your _main.cfg file, it's time to create your first scenario.
 
 
 
Create a new text file in the "scenarios" folder inside your campaign folder. Name this new text file "my_first_scenario.cfg". Open the "my_first_scenario.cfg" file in your text editor, if you haven't already. Since it is a new file, it should be completely empty right now. It won't be when we're done with it, however!
 
 
 
First, let's add the "scenario" tagset:
 
 
 
[scenario]
 
[/scenario]
 
 
 
The "scenario" tagset tells the game where the scenario begins and where it ends. All the information for your scenario goes within this tagset.
 
 
 
Next, inside the "scenario" tagset, include the following keys (don't forget to indent 4 spaces before each key):
 
id=
 
next_scenario=
 
name=
 
map_data=
 
turns=
 
 
 
Now the contents of the "my_first_scenario.cfg" file should look like this:
 
[scenario]
 
    id=
 
    next_scenario=
 
    name=
 
    map_data=
 
    turns=
 
[/scenario]
 
 
 
We have provided keys for these attributes, so now it's time to assign them their values.  
 
  
*'''The "id" Key'''
+
2. Finish chapters 6-11 (Partially Complete)
  
:Assign the value "my_first_scenario" to the "id" key, like so:
+
[[Category:WML_for_Complete_Beginners]]
id=my_first_scenario
 
:Do you remember the value we assigned to the "first_scenario" key in the "_main.cfg" file? If you followed the instructions given in this tutorial, the value of that key should be "my_first_tutorial". It is absolutely imperative that the value of the "first_scenario" key and the "id" key of the first scenario are exactly the same. If you misspelled either of them, introduced an incorrect capitalization into either of them, or made a typo of any kind in either of them, the game will return an error message when it tries to load the scenario. This is because the value of the "first_scenario" key refers to the id of your first scenario. If there is no scenario with an "id" key whose value exactly matches the value of the value of the "first_scenario" key, the game won't be able to find the first scenario.
 

Latest revision as of 18:56, 29 January 2023


Welcome to the WML Guide for Complete Beginners! From here, you can get started directly by heading to the Introduction or you can continue from the chapter you left off.

Main Index

Introduction
1 - Syntax
2 - The Userdata Directory and the Campaign Folder
3 - The _main.cfg
4 - Creating Your First Scenario
5 - Events
6 - Custom Units
7 - Variables Introduction
8 - Non-scalar Variables
9 - Macros
10 - Logic
11 - More Logic
Conclusion


Note for Improvements:

1. Add to the numbers definition that numbers can include decimal point values (and reference the fact that WML will remove any unnecessary 0's when it performs the calculations or accesses the numerical value in question).

2. Finish chapters 6-11 (Partially Complete)

This page was last edited on 29 January 2023, at 18:56.