OSP Code Optimisation Small enhancement to the module system

Users who are viewing this thread

One simple type of error that has wasted quite a bit of my time trying to debug is something like this:
Code:
(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:
Code:
  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".
 
Added that in and tested it out by inserting an example error.  It worked like a charm and will be very useful.  Thank you for the headache of some tomorrow that you've saved me from.

Edit: That change also showed there being a (try_end) missing in the native 1.143 module_scripts @ game_receive_network_message.  Looks like it was missing one at the end of that script.
 
Windyplains said:
Edit: That change also showed there being a (try_end) missing in the native 1.143 module_scripts @ game_receive_network_message.  Looks like it was missing one at the end of that script.
Hmm, you're right; I didn't test with native (the mod I work on has very major changes). Probably missing try_end at the very end of a script makes no difference in practice, but it might have some unknown side effects, like the call_script failing.
 
This will be a nice addition to my enhanced msys. Thanks again Vornne. Bookmarked.

POST: Looks like this resolves a small mystery, the weird behavior of some of the older scripts in SWC. The playerbase will appreciate it. :smile:
 
it also gives me warnings about mission_templates and dialogs, can you make something to tell the id of the dialog?
Code:
Initializing...
Compiling all global variables...
Exporting strings...
Exporting skills...
Exporting tracks...
Exporting animations...
Exporting meshes...
Exporting sounds...
Exporting skins...
Exporting map icons...
Creating new tag_uses.txt file...
Creating new quick_strings.txt file...
Exporting faction data...
Exporting item data...
Exporting scene data...
Exporting troops data
Exporting particle data...
Exporting scene props...
Exporting tableau materials data...
Exporting presentations...
Exporting party_template data...
Exporting parties
Exporting quest data...
Exporting info_page data...
Exporting scripts...
WARNING: 1 missing try_end: game_receive_network_message
WARNING: 2 missing try_end: apply_effect_of_other_people_on_courage_scores
WARNING: 1 missing try_end: update_mercenary_units_of_towns
WARNING: 2 missing try_end: internal_politics_rate_feast_to_s9
Exporting mission_template data...
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 extra try_end: 0
WARNING: 1 missing try_end: 0
Exporting game menus data...
WARNING: 1 missing try_end: 0
WARNING: 1 missing try_end: 0
exporting simple triggers...
exporting triggers...
exporting dialogs...
WARNING: 1 missing try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 missing try_end: 0
WARNING: 1 missing try_end: 0
Checking global variable usages...
Exporting postfx_params...
 
Code:
# 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------------"
#>

With this you should be able to locate easily the chunk.
Sadly the opcodes have been already translated in that stage. But variables help, a lot.
 
thank you Swyter, it helped me a lot, now it is something easier to solve... luckily the local_variables are not replaced yet.
It looks like this now:
Code:
Initializing...
Compiling all global variables...
Exporting strings...
Exporting skills...
Exporting tracks...
Exporting animations...
Exporting meshes...
Exporting sounds...
Exporting skins...
Exporting map icons...
Creating new tag_uses.txt file...
Creating new quick_strings.txt file...
Exporting faction data...
Exporting item data...
Exporting scene data...
Exporting troops data
Exporting particle data...
Exporting scene props...
Exporting tableau materials data...
Exporting presentations...
Exporting party_template data...
Exporting parties
Exporting quest data...
Exporting info_page data...
Exporting scripts...
WARNING: 1 missing try_end: game_receive_network_message
WARNING: 2 missing try_end: apply_effect_of_other_people_on_courage_scores
WARNING: 2 missing try_end: internal_politics_rate_feast_to_s9
Exporting mission_template data...
WARNING: 1 extra try_end:
------------
[(1710, 2, '$fplayer_agent_no'), (1726, ':shield_item', '$fplayer_agent_no', 1),
 (31, ':shield_item', 'itm_pavise'), (721, 2, 50), (1970, 2), (1974, 'spr_pavise
'), (1774, '$fplayer_agent_no', 'itm_pavise'), 3]
------------
WARNING: 1 missing try_end:
------------
[(1712, '$fplayer_agent_no'), (2170, ':leadership', 'skl_leadership', '$g_player
_troop'), (2121, ':cha_bonus', '$attribute', 0), (2107, ':leadership', 3), (12,
':cur_agent'), (1712, ':cur_agent'), (1702, ':cur_agent'), (1704, ':cur_agent'),
 (1706, ':cur_agent'), (2147483679L, ':cur_agent', '$fplayer_agent_no'), (1720,
':life', ':cur_agent', 0), 4, (1772, ':blah', ':cur_agent'), (2147483679L, ':bla
h', 2), (1740, ':cur_agent', 'anim_cheer'), (2105, ':life', ':cha_bonus'), (2105
, ':life', ':leadership'), (1721, ':cur_agent', ':life', 0), (1750, ':cur_agent'
, 'snd_man_victory'), 3, (2120, ':recovery', ':leadership', ':cha_bonus'), (2133
, 72057594037927937L, ':recovery'), (1106, '@You rally your men! (wounded troops
 recover {reg1} % hitpoints)'), (1, 'script_rage_exp_penalty')]
------------
WARNING: 1 extra try_end:
------------
[(1710, 2, '$fplayer_agent_no'), (1726, ':shield_item', '$fplayer_agent_no', 1),
 (31, ':shield_item', 'itm_pavise'), (721, 2, 50), (1970, 2), (1974, 'spr_pavise
'), (1774, '$fplayer_agent_no', 'itm_pavise'), 3]
------------
WARNING: 1 missing try_end:
------------
[(1712, '$fplayer_agent_no'), (2170, ':leadership', 'skl_leadership', '$g_player
_troop'), (2121, ':cha_bonus', '$attribute', 0), (2107, ':leadership', 3), (12,
':cur_agent'), (1712, ':cur_agent'), (1702, ':cur_agent'), (1704, ':cur_agent'),
 (1706, ':cur_agent'), (2147483679L, ':cur_agent', '$fplayer_agent_no'), (1720,
':life', ':cur_agent', 0), 4, (1772, ':blah', ':cur_agent'), (2147483679L, ':bla
h', 2), (1740, ':cur_agent', 'anim_cheer'), (2105, ':life', ':cha_bonus'), (2105
, ':life', ':leadership'), (1721, ':cur_agent', ':life', 0), (1750, ':cur_agent'
, 'snd_man_victory'), 3, (2120, ':recovery', ':leadership', ':cha_bonus'), (2133
, 72057594037927937L, ':recovery'), (1106, '@You rally your men! (wounded troops
 recover {reg1} % hitpoints)'), (1, 'script_rage_exp_penalty')]
------------
WARNING: 1 extra try_end:
------------
[(1710, 2, '$fplayer_agent_no'), (1726, ':shield_item', '$fplayer_agent_no', 1),
 (31, ':shield_item', 'itm_pavise'), (721, 2, 50), (1970, 2), (1974, 'spr_pavise
'), (1774, '$fplayer_agent_no', 'itm_pavise'), 3]
------------
WARNING: 1 missing try_end:
------------
[(1712, '$fplayer_agent_no'), (2170, ':leadership', 'skl_leadership', '$g_player
_troop'), (2121, ':cha_bonus', '$attribute', 0), (2107, ':leadership', 3), (12,
':cur_agent'), (1712, ':cur_agent'), (1702, ':cur_agent'), (1704, ':cur_agent'),
 (1706, ':cur_agent'), (2147483679L, ':cur_agent', '$fplayer_agent_no'), (1720,
':life', ':cur_agent', 0), 4, (1772, ':blah', ':cur_agent'), (2147483679L, ':bla
h', 2), (1740, ':cur_agent', 'anim_cheer'), (2105, ':life', ':cha_bonus'), (2105
, ':life', ':leadership'), (1721, ':cur_agent', ':life', 0), (1750, ':cur_agent'
, 'snd_man_victory'), 3, (2120, ':recovery', ':leadership', ':cha_bonus'), (2133
, 72057594037927937L, ':recovery'), (1106, '@You rally your men! (wounded troops
 recover {reg1} % hitpoints)'), (1, 'script_rage_exp_penalty')]
------------
but there is a lot after and it doesn't really fit the compiler screen :grin:

edit: already fixed all the dialog errors thanks to this...
 
I combined this with hackery (MSH:301) by kt0,
Here's the result of the compiling :
compiling.jpg


I shared the proccess_*.py on repository.
All credits for kt0 and Vornne.
 
Back
Top Bottom