Post by BonzaiRob on Feb 13, 2007 22:08:18 GMT
Yes, our engine is in Java, but the majority of custom work (that means maps, pokémon, moves, events, save files, bags, stats, you name it) is in XML.
Doesn't XML sound like a scary name? It stands for Xtraordinarily Murderous Lizard.
Actually, it's eXtensible Markup Language. That's not scary is it? Makes me think of marker pens (and grass, for some reason). Anyway, I'll shut up and get on with it. This will be your basic introduction to XML - how it works, the rules... the almighty word syntax is what we use for this.
If you've ever used HTML, XML will be easy-peasy in comparison. If not, well, keep reading.
The basis of HTML look like these: <>
That's because they are indeed <> - the less than and greater than signs used in maths. However, they don't mean less than and greater than here - they are used purely because they look cool. Isn't that great?
Anyway, we use the <> things in bits of code called tags. Tags are what identify information (like soldiers have those tag-things). A standard tag looks like this:
If you've ever used HTML, you'll know tags have to be <B></B> for bold, and so on. Well, the good news for HTML users is that in XML, you can make up your own tags!
If that made no sense to you, I'll explain. The first tag, <tag>, starts off the information, and then </tag> finishes it. What we usually do is put info between the tags, literally like this:
Simple, eh? A good example is the pokémon code, where we go <type1>Fire</type1> (or whatever the first type is).
There are rules for naming tags, though:
I am not a number! - you can't just have them as numbers, like <1></1>. You'd think that would be a bit stupid, right? I guess that's no twhat XML is designed for.
No spaces left. - no spaces in tag names. More on this later, but <tag name> </tag name> is wrong.
That's all very well, but we only have one kind of info there. What if we want two of more kinds?
Well, we can put two sorts of tags next to each other, like this:
You don't need to put them under each other, it's just easier to read. You can put entire XML files on one line, but only if you want to develop some kind of eye condition.
Another thing you can do is called nesting tags. That means, you put one sort of tag inside another, like this:
If you're writing in a dedicated XML or HTML program, it might indent the line for you when you press Return after <tag1>. Like the next line itself, you don't need to, it's just easier to read.
There are two main ways this can go wrong:
See what's up? instead of having the tag2 bits inside tag1, one's inside and one's outside. That will nicely break any computer program trying to read the file, so don't do that.
If you want to nest tags you can't put normal info in there with tags. The thing about nesting tags is that it's more useful for grouping things together. Example: in maps, we group things like so:
Hey, that's interesting! Sharp people among you might have noticed that there are two new things in the above example!
First of all, we have your new friend, the second type of tag. That is:
Now you can't have the first type of tags on their own, like <tag>. That's cus they open and close information. This guy, on the other hand, both opens and closes information at the same time. That's why there's a slash at the end, to show that's it.
New thing number two! Hey, isn't there information INSIDE those tags? Why yes there is! These things:
Are called Attributes! What fun we're having! The good things about attributes are:
Where do you want me? - You can put attributes inside either kind of tag. But, if you do it in the opening and closing kind, make sure it's in the first one, the opening one, like in the example earlier.
Numbers or letters? - you can put whatever information you like inside attributes, except "s, because it'll think it's the second quote mark and stop reading that attribute.
The rule for using attributes are that you have to put them inside quote marks - ""s. That's pretty much it! You can have as many attributes in a tag as you like. You might realise now why I said you couldn't have spaces in tag names - the program reading it would think it was an attribute, and then it would check for a value (that's whatever you put in the ="" bit) and then would throw a fit because it couldn't find one, and sulk until you restart the program. Seriously, this is what happens.
Now it's time to write something! It won't look very impressive, because XML is pure information (unlike HTML which is about displaying information).
Open up a blank document in Notepad (or TextEdit, or any bog standard text editor). Either write or copy/paste the following:
This is how we start EVERY XML file we ever write. What does it mean, I hear you cry (along with variations on "you're insane" and "I like cheesecake"). Overall, it pretty much means "I'm an XML file!" but bit-by-bit:
<?xml and ?> - this kind of means "this bit tells you about me".
version="1.0" - XML version 1. There's only 1 version right now, so that's what we're using.
encoding="iso-8859-1" - this is to do with different languages and special letters, like é and stuff. That's set to english/Roman letters, so we don't need to change it unless we decide to write XML in Russian. Which we won't.
The last part of XML is for me what makes XML writing fun.
Because I am a complete dork.
These are perhaps the third type of tag, and they are called comments. They're special, like this:
<!-- comments here -->
All you really need to know is that the <!-- starts it and the --> ends it. anything between the two won't be read by a computer program looking at the file (other than a text editor, otherwise there'd be no point). You can put pretty much whatever you like inside them. Here's an example, from the pokemon code file of Missingno.:
I've left that there as a note to anyone else reading the file. It's easier than having to refer to some other document about what to do, right? Right. Later on in that file, I go over the growth rates, base tameness, catch rate, all in comments.
In fact, most types of code have some sort of comments system, because it really is that useful, and if you're as nerdy as me you can write random crap in there without breaking whatever program reads it.
By the way, ignore the fact I don't know how we're coding height and weight yet >.>
I can't show you anything particularly magical or fantastic in this tutorial, but you get the idea now. This should give you some ideas for syntax. It doesn't mean anything, but yeah:
Hopefully, if you were paying attention, that all made sense! Now you can move on to another tutorial, once I write them >.>
Oh and by the way, XML files are read by a parser. Together with syntax, you can feel good because you added to your vocabulary today.
Doesn't XML sound like a scary name? It stands for Xtraordinarily Murderous Lizard.
Actually, it's eXtensible Markup Language. That's not scary is it? Makes me think of marker pens (and grass, for some reason). Anyway, I'll shut up and get on with it. This will be your basic introduction to XML - how it works, the rules... the almighty word syntax is what we use for this.
If you've ever used HTML, XML will be easy-peasy in comparison. If not, well, keep reading.
The basis of HTML look like these: <>
That's because they are indeed <> - the less than and greater than signs used in maths. However, they don't mean less than and greater than here - they are used purely because they look cool. Isn't that great?
Anyway, we use the <> things in bits of code called tags. Tags are what identify information (like soldiers have those tag-things). A standard tag looks like this:
<tag></tag>
If you've ever used HTML, you'll know tags have to be <B></B> for bold, and so on. Well, the good news for HTML users is that in XML, you can make up your own tags!
If that made no sense to you, I'll explain. The first tag, <tag>, starts off the information, and then </tag> finishes it. What we usually do is put info between the tags, literally like this:
<tag>information</tag>
Simple, eh? A good example is the pokémon code, where we go <type1>Fire</type1> (or whatever the first type is).
There are rules for naming tags, though:
I am not a number! - you can't just have them as numbers, like <1></1>. You'd think that would be a bit stupid, right? I guess that's no twhat XML is designed for.
No spaces left. - no spaces in tag names. More on this later, but <tag name> </tag name> is wrong.
That's all very well, but we only have one kind of info there. What if we want two of more kinds?
Well, we can put two sorts of tags next to each other, like this:
<tag1>info1</tag1>
<tag2info2</tag2>
You don't need to put them under each other, it's just easier to read. You can put entire XML files on one line, but only if you want to develop some kind of eye condition.
Another thing you can do is called nesting tags. That means, you put one sort of tag inside another, like this:
<tag1>
<tag2>info!</tag2>
</tag1>
If you're writing in a dedicated XML or HTML program, it might indent the line for you when you press Return after <tag1>. Like the next line itself, you don't need to, it's just easier to read.
There are two main ways this can go wrong:
<tag1><tag2>info!</tag1></tag2>
See what's up? instead of having the tag2 bits inside tag1, one's inside and one's outside. That will nicely break any computer program trying to read the file, so don't do that.
<tag1>information
<tag2>more info</tag2>
</tag1>
If you want to nest tags you can't put normal info in there with tags. The thing about nesting tags is that it's more useful for grouping things together. Example: in maps, we group things like so:
<group name="grasses">
<image image="tiles/grass2.gif" x="3" y="0" />
<image image="tiles/grass2.gif" x="4" y="0" />
<image image="tiles/grass2.gif" x="5" y="0" />
<image image="tiles/grass2.gif" x="6" y="0" />
</group>
Hey, that's interesting! Sharp people among you might have noticed that there are two new things in the above example!
First of all, we have your new friend, the second type of tag. That is:
<newtag />
Now you can't have the first type of tags on their own, like <tag>. That's cus they open and close information. This guy, on the other hand, both opens and closes information at the same time. That's why there's a slash at the end, to show that's it.
New thing number two! Hey, isn't there information INSIDE those tags? Why yes there is! These things:
<tag newthing="" />
Are called Attributes! What fun we're having! The good things about attributes are:
Where do you want me? - You can put attributes inside either kind of tag. But, if you do it in the opening and closing kind, make sure it's in the first one, the opening one, like in the example earlier.
Numbers or letters? - you can put whatever information you like inside attributes, except "s, because it'll think it's the second quote mark and stop reading that attribute.
The rule for using attributes are that you have to put them inside quote marks - ""s. That's pretty much it! You can have as many attributes in a tag as you like. You might realise now why I said you couldn't have spaces in tag names - the program reading it would think it was an attribute, and then it would check for a value (that's whatever you put in the ="" bit) and then would throw a fit because it couldn't find one, and sulk until you restart the program. Seriously, this is what happens.
Now it's time to write something! It won't look very impressive, because XML is pure information (unlike HTML which is about displaying information).
Open up a blank document in Notepad (or TextEdit, or any bog standard text editor). Either write or copy/paste the following:
<?xml version="1.0" encoding="iso-8859-1" ?>
This is how we start EVERY XML file we ever write. What does it mean, I hear you cry (along with variations on "you're insane" and "I like cheesecake"). Overall, it pretty much means "I'm an XML file!" but bit-by-bit:
<?xml and ?> - this kind of means "this bit tells you about me".
version="1.0" - XML version 1. There's only 1 version right now, so that's what we're using.
encoding="iso-8859-1" - this is to do with different languages and special letters, like é and stuff. That's set to english/Roman letters, so we don't need to change it unless we decide to write XML in Russian. Which we won't.
The last part of XML is for me what makes XML writing fun.
Because I am a complete dork.
These are perhaps the third type of tag, and they are called comments. They're special, like this:
<!-- comments here -->
All you really need to know is that the <!-- starts it and the --> ends it. anything between the two won't be read by a computer program looking at the file (other than a text editor, otherwise there'd be no point). You can put pretty much whatever you like inside them. Here's an example, from the pokemon code file of Missingno.:
<species>Test</species>
<height>0 00</height> <!-- leave this for now, it's complicated :( -->
<weight>0 00</weight>
I've left that there as a note to anyone else reading the file. It's easier than having to refer to some other document about what to do, right? Right. Later on in that file, I go over the growth rates, base tameness, catch rate, all in comments.
In fact, most types of code have some sort of comments system, because it really is that useful, and if you're as nerdy as me you can write random crap in there without breaking whatever program reads it.
By the way, ignore the fact I don't know how we're coding height and weight yet >.>
I can't show you anything particularly magical or fantastic in this tutorial, but you get the idea now. This should give you some ideas for syntax. It doesn't mean anything, but yeah:
<?xml version="1.0" encoding="iso-8859-1" ?>
<tag1 attribute="This is tag 1!">
<tag2 number="1" />
<tag2 number="2" />
<tag2 number="3" />
<tag2 number="4" />
<!-- this is a boring XML file. I give up LOLZ -->
</tag1>
Hopefully, if you were paying attention, that all made sense! Now you can move on to another tutorial, once I write them >.>
Oh and by the way, XML files are read by a parser. Together with syntax, you can feel good because you added to your vocabulary today.