How to solve WML errors

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.

How to solve WML errors

Postby zookeeper » January 20th, 2007, 6:35 pm

Does you campaign produce obscure WML errors on startup and you don't know what line in your 2000 lines of WML causes it? Instead of going through everything line by line and try to spot the mistake you've made, or before posting your entire campaign on the forums in the hopes that someone wants to do it for you, try this instead:

Safety precautions: backup your campaign. Not necessary if you really trust the undo capabilities of your editor.

1. Remove half or more of the WML of your campaign. For example, remove every scenario other than the first one.
2. Test if you still get errors.
3. If you still got the error, then you know the error is in the parts that are still remaining. Go back to step 2 and again remove as much as you easily can (for example, cut away all the [event]s of that scenario you have left). Repeat until you've isolated the bug to a small enough section that you can easily just go through it line by line.
4. If you didn't get the error anymore, then you know you've just removed the part containing the error. Restore it, and then go to step 2 and apply that procedure to that part only. Repeat until you've isolated the bug to a small enough section that you can easily just go through it line by line.

This is a surprisingly quick and easy method of debugging obscure errors the source of which you can't really locate based on the error message. Mostly useful for campaigns, since they can contain large amounts of WML, but can just as well be used in debugging of single MP scenarios, for example. If you still cannot find what's wrong, then of course you can ask here on the forums, but you should still try to isolate the problem as well as you can beforehand to make helping you easier for others (it's not fun to dig through a 1000 lines of unfamiliar WML, if the one asking for help could have easily just trimmed that down to 200 lines first).

Of course, the easiest way of debugging is still to always test your stuff after making changes, so you will spot bugs as you make them and don't need to hunt for them later on.

EDIT
renamed thread title to "How to solve WML errors"
Last edited by zookeeper on November 13th, 2007, 2:15 pm, edited 1 time in total.
User avatar
zookeeper
WML Wizard
 
Posts: 9616
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Postby gadget005 » January 20th, 2007, 6:38 pm

Should have thought of that before sticking my 1000+ line cfg file on the forum. Apologies.

Thanks for your words of wisdom!
Creator of The Invasion of Elkoraz campaign.

If all the world is a stage, I want better lighting.
gadget005
 
Posts: 14
Joined: January 15th, 2007, 1:35 pm
Location: England

Postby Finisterrex » June 7th, 2007, 11:56 am

Yesterday it happens to me xD

i started reading all lines, but then i cut the WML as u said, and at the final i get the error... an "asdasdasd" typed by error lol.
Finisterrex
 
Posts: 15
Joined: June 7th, 2007, 11:44 am

i think there is another good way

Postby toni » June 8th, 2007, 7:58 pm

i think when people have .cfg-files with more than 1500 lines (my case), you should copy the lines where you think there is the bug (might be the lines you added last). then you test this lines in another scenario. it's another way. i just wanted to say this.
aka mysticspiral
toni
 
Posts: 42
Joined: April 13th, 2007, 7:28 pm
Location: berlin, germany

something that I've noticed

Postby Beastss » January 7th, 2008, 2:28 am

well, a little something that I noticed is that if you're using Wesnoth (1.2.8) and Windows notepad as the editor (me). Then when you get the error message, it usually tells you the tag that is either still open, or improperly closed. If you read the message a little more then it tells you a general line number. In some cases, it tells you the exact line that is still open/closed. In others it just tells you the basic group that its in, like it'll say "...line 2455..." and the only tag there is like message or something. Well, what it really means it that the problem is somewhere between whatever tag is open at 'line 2455' and its closing tag. Now the only problem is locating it.

If you're looking for a certain line, and using Windows notepad, then this is solved easily. Just go to 'View' and make sure 'Status Bar' is selected. At the bottom of notepad will be a status bar that tells you what line you're on and even what character you're on.

Now if you have the more difficult problem of having to find where it is between that set of code, then all you really have to do is look.

There's my simple way of solving some of the WML problems I run in to. Hope it helps some of you.
Beastss
 
Posts: 15
Joined: December 23rd, 2007, 9:57 am

Re: How to easily debug WML

Postby Suukorak » May 6th, 2009, 9:52 pm

zookeeper wrote:Does you campaign produce obscure WML errors on startup and you don't know what line in your 2000 lines of WML causes it? Instead of going through everything line by line and try to spot the mistake you've made, or before posting your entire campaign on the forums in the hopes that someone wants to do it for you, try this instead:

Safety precautions: backup your campaign. Not necessary if you really trust the undo capabilities of your editor.

1. Remove half or more of the WML of your campaign. For example, remove every scenario other than the first one.
2. Test if you still get errors.
3. If you still got the error, then you know the error is in the parts that are still remaining. Go back to step 2 and again remove as much as you easily can (for example, cut away all the [event]s of that scenario you have left). Repeat until you've isolated the bug to a small enough section that you can easily just go through it line by line.
4. If you didn't get the error anymore, then you know you've just removed the part containing the error. Restore it, and then go to step 2 and apply that procedure to that part only. Repeat until you've isolated the bug to a small enough section that you can easily just go through it line by line.

This is a surprisingly quick and easy method of debugging obscure errors the source of which you can't really locate based on the error message. Mostly useful for campaigns, since they can contain large amounts of WML, but can just as well be used in debugging of single MP scenarios, for example. If you still cannot find what's wrong, then of course you can ask here on the forums, but you should still try to isolate the problem as well as you can beforehand to make helping you easier for others (it's not fun to dig through a 1000 lines of unfamiliar WML, if the one asking for help could have easily just trimmed that down to 200 lines first).

Of course, the easiest way of debugging is still to always test your stuff after making changes, so you will spot bugs as you make them and don't need to hunt for them later on.


So this was the sticky you meant. Sorry, zookeeper and all!
:?
He who is still learning WML, can still make a campaign. (or at least try)

You are an Arch Mage - You're definitely intelligent, but some people would say you spend too much time inside. The power you have learned, however, is simply unmatched.
User avatar
Suukorak
 
Posts: 65
Joined: April 13th, 2009, 10:01 pm

Re: How to easily debug WML

Postby Sapient » June 20th, 2009, 11:36 pm

For the record, it is a lot easier to spot missing quote strings and missing end tags if you use a text editor with Syntax Highlighting or if you run Wesnoth's wmllint or wmliterator.py (a Maintenance tool distributed with the game).
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
User avatar
Sapient
Developer
 
Posts: 4369
Joined: November 26th, 2005, 7:41 am

Re: How to easily debug WML

Postby solsword » September 30th, 2009, 7:16 pm

Something that seems to be cropping up a lot recently:

The game will crash with an error message about a missing closing tag. The line number will be randomly somewhere in the middle of your scenario. There won't be anything wrong on that line, and the tag named in the error will be properly closed.

In this case, make sure you look at the full error output from Wesnoth. Most of the time, the error that is displayed in-game is the last of a series of errors, all of which are printed to the standard error output. If you fix these errors starting with the first one displayed, the later errors, including the "missing closing tag" error, are likely to vanish, as they may have been caused by the earlier errors.

To view the full error output:

On Windows: when you run the game and it crashes, it should create a file called "stderr.txt". Look here for the output.
Other operating systems: Launch the game from a terminal, and the error output will be displayed in the terminal.

Please correct me if I'm wrong about the above, as I couldn't find anything about this on the Wiki, and I don't have a Windows box.
User avatar
solsword
Code Contributor
 
Posts: 291
Joined: January 12th, 2009, 10:21 pm
Location: Santa Cruz, CA

Re: How to easily debug WML

Postby fog_of_gold » January 30th, 2010, 8:04 pm

Another way to delete large texts is this:
Code: Select all
#define comment
-[i]wrong text[/i]
#enddef

Of course, you mustn't use {comment}.

Edit: you can also use a '#ifdef XXX' but there's a small chance that others made a macro called 'XXX' even if it's sometimes used in the mainline.
fog_of_gold
 
Posts: 637
Joined: December 20th, 2009, 5:59 pm
Location: Germany

Re: How to easily debug WML

Postby SpoOkyMagician » March 28th, 2010, 3:20 am

personally, I find the "stderr.txt" the easiest/best way to debug WML errors. There shouldn't be any need to remove half the code and whatnot as suggested above. Unless, you are VERY NEW to WML or have MAJOR WML ERRORS... (Just make sure you follow the error output in order. Top first then go down. The errors under may be caused by the first error. Example: Sometimes you get errors such as; "missing closing tag multiplayer". If you did close the tag, ignore the error.)

edit: The only other exception that could cause problems can be duplicated id's or many different add-ons conflicting with one another. In this case, cut/paste your add-on's onto your desktop and put one addon in at a time. Attempt to figure out which add-on is causing the problem. (if stderr.txt is no help to you.)

Note that if wesnoth does not show an error during the loading process, that DOES NOT mean that there are still possible errors. Give the scenario/campaign/etc a test run and look though the stderr.txt afterwords. (DO NOT RESTART WESNOTH AFTER THE TEST OR YOU WILL LOSE ALL THE RESULTS.) The possible runtime WML errors will be shown in the log. (if any) Check what could be causing the problem and make your changes. Test run once again. (Repeat until all errors are gone/undetectable.)

Wesnoth 1.6.5 note (windows) Ignore this error:

20100327 23:27:32 error filesystem: Could not open 'C:/Users/<USERNAME>/Documents/My Games/Wesnoth1.6/editor/maps/' for reading.


I believe this is just a 1.6.5/windows related bug. I didn't notice this error in 1.7.15 with windows. (It will continually generate the line above so ignore those lines.)

This is the way I debug WML. I DO NOT TOLERATE any WML bugs in my stderr.txt or I do not release them unless they are only minor. (But, this is just the way i debug. You can ignore the runtime errors if you wish but, it will only lead to future problems if/when WML is updated...)

edit: Always check the reference wiki if you are unsure about any attributes/tags/etc related errors. (http://wiki.wesnoth.org/ReferenceWML) Just note that some attributes/tags/etc can be outdated or not available depending on which version of wesnoth you are using.

edit: If you find any WML errors related to downloaded add-on's, feel free to contact the author or post a reply in their topic of the add-on. Please make sure that you are very clear on what the problem is and copy/paste related stderr.txt error messages. If you are experienced with WML, also explain to them what is causing the problem just in case they are new to WML as well. (If you are 100% sure what is causing the problem.)
"You don't have to understand me, I'm just there!" ~ SpoOkyMagician
Creator of: Unwelcome Guests Series, Modifiable Android Project, SpoOky's Survivals, and many more... (Most of my old stuff is gone.)
(User Page)
User avatar
SpoOkyMagician
 
Posts: 281
Joined: September 5th, 2008, 8:04 am
Location: I have no idea...

Re: How to easily debug WML

Postby fog_of_gold » March 31st, 2010, 7:20 pm

There are errors not listed in stderr.txt. These errors are, if your code haven't got mistakes but it just don't work like you'd like to have and you don't know why.
fog_of_gold
 
Posts: 637
Joined: December 20th, 2009, 5:59 pm
Location: Germany

Re: How to easily debug WML

Postby bigkahuna » October 15th, 2010, 1:32 pm

This is NOT thread necroing, since this thread is a sticky :)

As a few people have mentioned above, cutting out half your scenario code isn't completely necessary, and can sometimes cause the scenario to not run at all (if you have to take out crucial events). Perhaps a footnote on how to debug errors themselves? Here are some notes I found useful from writing campaigns:

Campaign Debugging
1. If you get an error, first check the line number referenced on the main wesnoth screen.
NOTE: #1 could be an irrelevant error: Sometimes it says a completely random thing is wrong, when in fact a quote is misplaced or an id tag is wrong.

2. Check the stderr.txt and fix those errors. These are usually the main errors messing up the campaigns.

3. After this is done, run the campaign again. You will probably get more errors. This is because the game engine processes different parts of the campaign at different times; once you fix one part, it freezes at the next. Repeat #1 and #2.

Irrelevant errors:

"Missing closing tag on [???] on line ???" - some of the times these are relevant, but if you do have the closing tag, it is an error inside of those tags.

"Error with clear_variable" - It usually references a macro, such as {MOVE_UNIT} or {MODIFY_UNIT}. The error is most likely an error with a macro calling the wrong number of arguments (like {MOVE_UNIT ID X Y} , if you leave one of those arguments out you get this error). This is a hard error to fix.

Any random error that you know for a fact is not relevant: Sometimes wesnoth calls an irrelevant error when there is a separate error going on besides the ones mentioned above. This is why you also need to check the stderr.txt.
Last edited by bigkahuna on October 15th, 2010, 3:45 pm, edited 3 times in total.
Check out my campaign Sweet Revenge!
Join the new R2D forum!
User avatar
bigkahuna
 
Posts: 657
Joined: September 11th, 2010, 6:24 pm
Location: In your mind.

Re: How to easily debug WML

Postby bumbadadabum » October 15th, 2010, 3:06 pm

Personally, I've never debugged that way. The in-game error logs always work fine. (Surely if you use 1.9, all the bugs and error will be highlighted 1 by 1)
User avatar
bumbadadabum
Developer
 
Posts: 1004
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Re: How to easily debug WML

Postby bigkahuna » October 15th, 2010, 3:26 pm

I'm using 1.8... you have an in-game error log?!?!? WITH HIGHLIGHT?!?

I'm jealous.

All the good add-ons are still on 1.8, though, except for the few ported over by the over-achievers.
Check out my campaign Sweet Revenge!
Join the new R2D forum!
User avatar
bigkahuna
 
Posts: 657
Joined: September 11th, 2010, 6:24 pm
Location: In your mind.

Re: How to easily debug WML

Postby bumbadadabum » October 15th, 2010, 3:42 pm

bigkahuna wrote:I'm using 1.8... you have an in-game error log?!?!? WITH HIGHLIGHT?!?

I'm jealous.

All the good add-ons are still on 1.8, though, except for the few ported over by the over-achievers.

Just the same system as 1.8, only it shows every single things that causes errors or won't work.
User avatar
bumbadadabum
Developer
 
Posts: 1004
Joined: March 20th, 2008, 5:54 pm
Location: Netherlands

Next

Return to WML Workshop

Who is online

Users browsing this forum: No registered users and 2 guests