Core Module System Enhancements
Contents |
[edit] Notice
Quoting Vornne in first person. You can rephrase it if you want.
[edit] Article
One simple type of error that has wasted quite a bit of my time trying to debug is something like this:
(try_begin), ... (else_try), ... (try_end), ... (try_end),
Where I have added an extra try block to the group but mistakenly used try_end instead of else try.
Consistent indentation makes most other errors related to mismatched try operations obvious, but this one has caught me out a few times by now.
So I decided to add a check for it in the module building code, which was surprisingly simple: open process_operations.py, scroll down near the bottom to the "save_statement_block" function definition, and add this to the end of it:
if current_depth != 0: if current_depth > 0: missing = " missing" else: missing = " extra" current_depth *= -1 print "WARNING: " + `current_depth` + missing + " try_end: " + str(statement_name)
For the mistake above, building the module will output an error like "WARNING: 1 extra try_end: script_name".
[edit] Enhanced version
Just made a little variation so it shows the bad code if the logic error is located out of module_scripts.py
# Indentation Enhancement By Vorne # http://forums.taleworlds.com/index.php/topic,189368.0.html if current_depth != 0: if current_depth > 0: missing = " missing" else: missing = " extra" current_depth *= -1 if statement_name != 0: print "WARNING: " + `current_depth` + missing + " try_end: " + str(statement_name) else: print "WARNING: " + `current_depth` + missing + " try_end: \r\n------------\r\n" + str(statement_block) + "\r\n------------" #>
--Swyter 12:35, 20 August 2011 (CEST)
[edit] Source
The original article, by courtesy of Vornne, can be located here:
http://forums.taleworlds.com/index.php/topic,189368.0.html