New Module System Compiler Development

Users who are viewing this thread

Status
Not open for further replies.
The error message's given by the compiler can be somewhat misleading, as the line # does not correlate with the actual line in the module system.

When using an unassigned local variable, it will give the following screen:

2cx9bmt.jpg

The third error and all the ones below point to unassigned local variables in the mnu_village_center, but for example in line 38 in that menu, there is something completely different.

mnu_village_center (line 38, which should have an error is bolded):
      ("village_center",[(neg|party_slot_eq, "$current_town", slot_village_state, svs_looted),
                        (neg|party_slot_eq, "$current_town", slot_village_state, svs_being_raided),
                        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),]
      ,"Go to the village center.",
      [
        (try_begin),
          (call_script, "script_cf_enter_center_location_bandit_check"),
        (else_try),
          (party_get_slot, ":village_scene", "$current_town", slot_castle_exterior),
          (modify_visitors_at_site,":village_scene"),
          (reset_visitors),
          (party_get_slot, ":village_elder_troop", "$current_town",slot_town_elder),
          (set_visitor, 11, ":village_elder_troop"),
            ##diplomacy begin
          (try_begin),
            (gt, "$g_player_chamberlain", 0),
            (call_script, "script_dplmc_appoint_chamberlain"),  #fix for wrong troops after update
            (party_get_slot, ":town_lord", "$current_town", slot_town_lord),
            (eq, ":town_lord", "trp_player"),
            (set_visitor, 9, "$g_player_chamberlain"),
          (try_end),
            ##diplomacy end


          (call_script, "script_init_town_walkers"),

          (try_begin),
            (check_quest_active, "qst_hunt_down_fugitive"),
            (neg|is_currently_night),
            (quest_slot_eq, "qst_hunt_down_fugitive", slot_quest_target_center, "$current_town"),
            (neg|check_quest_succeeded, "qst_hunt_down_fugitive"),
            (neg|check_quest_failed, "qst_hunt_down_fugitive"),
            (set_visitor, 45, "trp_fugitive"),
          (try_end),

          (set_jump_mission,"mt_village_center"),
#F&B begin
############### dividing the scene into 25 quadrants ################### this is line 38
(get_scene_boundaries, pos36, pos37),
(assign, pos1, pos36),
(assign, pos34, pos37),
(assign, ":scene_max", pos37),
(assign, ":scene_min", pos36),
(assign, reg25, pos36),
(assign, reg26, pos37),
(display_message, "@ min: {reg25}, max: {reg26}"),
(position_get_x, ":min_x", ":scene_min"),
(position_get_y, ":min_y", ":scene_min"),
(position_get_x, ":max_x" ":scene_max"),
(position_get_y, ":max_y", ":scene_max"),

(assign, ":diff_x", ":max_x"),
(assign, ":diff_y", ":max_y"),
(val_sub, ":diff_x", ":min_x"),
(val_div, ":diff_x", 5),
(val_sub, ":diff_y", ":min_y"),
(val_div, ":diff_y", 5),

(assign, ":mad:_off1", ":diff_x"),
(assign, ":y_off1", ":diff_y"),
(val_add, ":mad:_off1", ":min_x"),
(val_add, ":y_off1", ":min_y"),

(assign, ":mad:_off2", ":mad:_off1"),
(assign, ":y_off2", ":y_off1"),
(val_add, ":mad:_off2", ":diff_x"),
(val_add, ":y_off2", ":diff_y"),

(assign, ":mad:_off3", ":mad:_off2"),
(assign, ":y_off3", ":y_off2"),
(val_add, ":mad:_off3", ":diff_x"),
(val_add, ":y_off3", ":diff_y"),

(assign, ":mad:_off4", ":mad:_off3"),
(assign, ":y_off4", ":y_off3"),
(val_add, ":mad:_off4", ":diff_x"),
(val_add, ":y_off4", ":diff_y"),
################ Defining the positions pos2-33
(position_set_x, pos2, ":mad:_off1"),
(position_set_y, pos2, ":min_y"),

(position_set_x, pos3, ":mad:_off2"),
(position_set_y, pos3, ":min_y"),

(position_set_x, pos4, ":mad:_off3"),
(position_set_y, pos4, ":min_y"),

(position_set_x, pos5, ":mad:_off4"),
(position_set_y, pos5, ":min_y"),

(position_set_x, pos6, ":min_x"),
(position_set_y, pos6, ":y_off1"),

(position_set_x, pos7, ":mad:_off1"),
(position_set_x, pos7, ":y_off1"),

(position_set_x, pos8, ":mad:_off2"),
(position_set_y, pos8, ":y_off1"),

(position_set_x, pos9, ":mad:_off3"),
(position_set_y, pos9, ":y_off1"),

(position_set_x, pos10, ":mad:_off4"),
(position_set_y, pos10, ":y_off1"),

(position_set_x, pos11, ":max_x"),
(position_set_y, pos11, ":y_off1"),

(position_set_x, pos12, ":min_x"),
(position_set_y, pos12, ":y_off2"),

(position_set_x, pos13, ":mad:_off1"),
(position_set_y, pos13, ":y_off2"),

(position_set_x, pos14, ":mad:_off2"),
(position_set_y, pos14, ":y_off2"),

(position_set_x, pos15, ":mad:_off3"),
(position_set_y, pos15, ":y_off2"),

(position_set_x, pos16, ":mad:_off4"),
(position_set_y, pos16, ":y_off2"),

(position_set_x, pos17, ":max_x"),
(position_set_y, pos17, ":y_off2"),

(position_set_x, pos18, ":min_x"),
(position_set_y, pos18, ":y_off3"),

(position_set_x, pos19, ":mad:_off1"),
(position_set_y, pos19, ":y_off3"),

(position_set_x, pos20, ":mad:_off2"),
(position_set_y, pos20, ":y_off3"),

(position_set_x, pos21, ":mad:_off3"),
(position_set_y, pos21, ":y_off3"),

(position_set_x, pos22, ":mad:_off4"),
(position_set_y, pos22, ":y_off3"),

(position_set_x, pos23, ":max_x"),
(position_set_y, pos23, ":y_off3"),

(position_set_x, pos24, ":min_x"),
(position_set_y, pos24, ":y_off4"),

(position_set_x, pos25, ":mad:_off1"),
(position_set_y, pos25, ":y_off4"),

(position_set_x, pos26, ":mad:_off2"),
(position_set_y, pos26, ":y_off4"),

(position_set_x, pos27, ":mad:_off3"),
(position_set_y, pos27, ":y_off4"),

(position_set_x, pos28, ":mad:_off4"),
(position_set_y, pos28, ":y_off4"),

(position_set_x, pos29, ":max_x"),
(position_set_y, pos29, ":y_off4"),

(position_set_x, pos30, ":mad:_off1"),
(position_set_y, pos30, ":max_y"),

(position_set_x, pos31, ":mad:_off2"),
(position_set_y, pos31, ":max_y"),

(position_set_x, pos32, ":mad:_off3"),
(position_set_y, pos32, ":max_y"),

(position_set_x, pos33, ":mad:_off4"),
(position_set_y, pos33, ":max_y"),
############### Creating prop counter variables
(assign, ":q1_prop_amount", 0),
(assign, ":q2_prop_amount", 0),
(assign, ":q3_prop_amount", 0),
(assign, ":q4_prop_amount", 0),
(assign, ":q5_prop_amount", 0),
(assign, ":q6_prop_amount", 0),
(assign, ":q7_prop_amount", 0),
(assign, ":q8_prop_amount", 0),
(assign, ":q9_prop_amount", 0),
(assign, ":q10_prop_amount", 0),
(assign, ":q11_prop_amount", 0),
(assign, ":q12_prop_amount", 0),
(assign, ":q13_prop_amount", 0),
(assign, ":q14_prop_amount", 0),
(assign, ":q15_prop_amount", 0),
(assign, ":q16_prop_amount", 0),
(assign, ":q17_prop_amount", 0),
(assign, ":q18_prop_amount", 0),
(assign, ":q19_prop_amount", 0),
(assign, ":q20_prop_amount", 0),
(assign, ":q21_prop_amount", 0),
(assign, ":q22_prop_amount", 0),
(assign, ":q23_prop_amount", 0),
(assign, ":q24_prop_amount", 0),
(assign, ":q25_prop_amount", 0),

############### iterating through all scene_props and counting the scene_prop density for each quadrant
(try_for_range, ":scene_prop", "spr_barrier_20m", "spr_mine_a"),
(prop_instance_is_valid, ":scene_prop"),
(prop_instance_get_position, pos35, ":scene_prop"),

(try_begin),
(is_between, pos35, pos1, pos7),
(val_add, ":q1_prop_amount", 1),
(else_try),
(is_between, pos35, pos2, pos:cool:,
(val_add, ":q2_prop_amount", 1),
(else_try),
(is_between, pos35, pos3, pos9),
(val_add, ":q3_prop_amount", 1),
(else_try),
(is_between, pos35, pos4, pos10),
(val_add, ":q4_prop_amount", 1),
(else_try),
(is_between, pos35, pos5, pos11),
(val_add, ":q5_prop_amount", 1),
(else_try),
(is_between, pos35, pos6, pos13),
(val_add, ":q6_prop_amount", 1),
(else_try),
(is_between, pos35, pos7, pos14),
(val_add, ":q7_prop_amount", 1),
(else_try),
(is_between, pos35, pos8, pos15),
(val_add, ":q8_prop_amount", 1),
(else_try),
(is_between, pos35, pos9, pos16),
(val_add, ":q9_prop_amount", 1),
(else_try),
(is_between, pos35, pos10, pos17),
(val_add, ":q10_prop_amount", 1),
(else_try),
(is_between, pos35, pos12, pos19),
(val_add, ":q11_prop_amount", 1),
(else_try),
(is_between, pos35, pos13, pos20),
(val_add, ":q12_prop_amount", 1),
(else_try),
(is_between, pos35, pos14, pos21),
(val_add, ":q13_prop_amount", 1),
(else_try),
(is_between, pos35, pos15, pos22),
(val_add, ":q14_prop_amount", 1),
(else_try),
(is_between, pos35, pos16, pos23),
(val_add, ":q15_prop_amount", 1),
(else_try),
(is_between, pos35, pos18, pos25),
(val_add, ":q16_prop_amount", 1),
(else_try),
(is_between, pos35, pos19, pos26),
(val_add, ":q17_prop_amount", 1),
(else_try),
(is_between, pos35, pos20, pos27),
(val_add, ":q18_prop_amount", 1),
(else_try),
(is_between, pos35, pos21, pos2:cool:,
(val_add, ":q19_prop_amount", 1),
(else_try),
(is_between, pos35, pos22, pos29),
(val_add, ":q20_prop_amount", 1),
(else_try),
(is_between, pos35, pos24, pos30),
(val_add, ":q21_prop_amount", 1),
(else_try),
(is_between, pos35, pos25, pos31),
(val_add, ":q22_prop_amount", 1),
(else_try),
(is_between, pos35, pos26, pos32),
(val_add, ":q23_prop_amount", 1),
(else_try),
(is_between, pos35, pos27, pos33),
(val_add, ":q24_prop_amount", 1),
(else_try),
(is_between, pos35, pos28, pos34),
(val_add, ":q25_prop_amount", 1),
(try_end),
(try_end),
############### Debug
#(try_for_range, ":prop_amount", ":q1_prop_amount", ":q25_prop_amount"),
#(store_sub, ":eek:ffset", ":prop_amount", ":q1_prop_amount"),
#(store_add, ":reg", reg0, ":eek:ffset"),
#(assign, ":reg",


(assign, reg0, ":q1_prop_amount"),
(assign, reg1, ":q2_prop_amount"),
(assign, reg2, ":q3_prop_amount"),
(assign, reg3, ":q4_prop_amount"),
(assign, reg4, ":q5_prop_amount"),
(assign, reg5, ":q6_prop_amount"),
(assign, reg6, ":q7_prop_amount"),
(assign, reg7, ":q8_prop_amount"),
(assign, reg8, ":q9_prop_amount"),
(assign, reg9, ":q10_prop_amount"),
(assign, reg10, ":q11_prop_amount"),
(assign, reg11, ":q12_prop_amount"),
(assign, reg12, ":q13_prop_amount"),
(assign, reg13, ":q14_prop_amount"),
(assign, reg14, ":q15_prop_amount"),
(assign, reg15, ":q16_prop_amount"),
(assign, reg16, ":q17_prop_amount"),
(assign, reg17, ":q18_prop_amount"),
(assign, reg18, ":q19_prop_amount"),
(assign, reg19, ":q20_prop_amount"),
(assign, reg20, ":q21_prop_amount"),
(assign, reg21, ":q22_prop_amount"),
(assign, reg22, ":q23_prop_amount"),
(assign, reg23, ":q24_prop_amount"),
(assign, reg24, ":q25_prop_amount"),

(display_message, "@ q1:{reg0}, q2:{reg1}, q3:{reg2}, q4:{reg3}, q5:{reg4}, q6:{reg5}, q7:{reg6}, q8:{reg7}, q9:{reg8}, q10:{reg9},\
q11:{reg10}, q12:{reg11}, q13:{reg12}, q14:{reg13}, q15:{reg14}, q16:{reg15}, q17:{reg16}, q18:{reg17}, q19:{reg18}, q20:{reg19},\
q21:{reg20}, q22:{reg21}, q23:{reg22}, q24:{reg23}, q25:{reg24}"),
#(prop_instance_get_position, pos6, ":scene_prop_id"),
########################################################
#F&B end  
          (jump_to_scene,":village_scene"),
          (change_screen_mission),
        (try_end),
        ],"Door to the village center."),
      ##diplomacy begin
      ("dplmc_village_elder_meeting",[
        (neg|party_slot_eq, "$current_town", slot_village_state, svs_looted),
        (neg|party_slot_eq, "$current_town", slot_village_state, svs_being_raided),
        (neg|party_slot_ge, "$current_town", slot_village_infested_by_bandits, 1),
  ##diplomacy start+
#rubik had a good idea: only enable this after having met the village elder
(party_get_slot, ":village_elder_troop", "$current_town",slot_town_elder),
(gt, ":village_elder_troop", 0),
(this_or_next|eq, "$cheat_mode", 1),#Always can jump to village elder in cheat mode
    (troop_slot_ge,":village_elder_troop", slot_troop_met, 1),
##diplomacy end+
      ]

Edit:

It may be more useful to show the total line #, instead of a local line #, for these kind of errors.

Still, the error condensing is working great. In comparison, the native compiler filled the whole window with errors, all because of one missing ",".
 
Fire_and_Blood said:
The error message's given by the compiler can be somewhat misleading, as the line # does not correlate with the actual line in the module system.

It may be more useful to show the total line #, instead of a local line #, for these kind of errors.
Yes, there's unfortunately little I can do to fix this - compiler does not interact with the module files on the same level as Python engine does. So what it reports (and what vanilla compiler reports in the same situation) is the number of operation within the code block that's causing the issue. I'm afraid that's the best anyone can do here without some serious code hacking involved.

Ikaguia said:
those two first errors are from native AFAIK. I have them also in my mod.
Yes, they're both from Native. Neither is causing any issues for the code so they can be safely ignored.
 
To make the code more clean, is it possible to add a warning for unused variables?

Comparison of native and new compiler compiling the same ms:

2pqufsy.png
 
Currently playing with syntax extension feature in preparation for official compiler release.

Showcase of the day: a plugin (still in development) introducing various useful functionality. A global stack, unlimited number of mission timers and several new operations: get_fixed_point_multiplier (credit to motomataru), position_set_coordinates (set all three coordinates of a position in a single operation), troop_set_attribute and troop_set_skill operations to set attribute/skill to specified fixed value.

Code:
from compiler import *
register_plugin(__name__)


troops = [
    ["stack_storage_troop", "{!}disabled", "{!}disabled", tf_hero|tf_inactive, 0, 0, 0, [], 0, 0, 0, 0],
    ["timer_storage_troop", "{!}disabled", "{!}disabled", tf_hero|tf_inactive, 0, 0, 0, [], 0, 0, 0, 0],
]

stack_storage = trp.stack_storage_troop
timer_storage = trp.timer_storage_troop


# Global stack operations

def push_value(value, *argl):
    return [
        (troop_get_slot, l._cached_, stack_storage, 0),
        (val_add, l._cached_, 1),
        (troop_set_slot, stack_storage, 0, l._cached_),
        (troop_set_slot, stack_storage, l._cached_, value),
    ]
def pop_value(destination, *argl):
    return [
        (troop_get_slot, l._cached_, stack_storage, 0),
        (troop_get_slot, l.destination, stack_storage, l._cached_),
        (val_sub, l._cached_, 1),
        (troop_set_slot, stack_storage, 0, l._cached_),
    ]
def peek_value(destination, *argl):
    return [
        (troop_get_slot, l._cached_, stack_storage, 0),
        (troop_get_slot, l.destination, stack_storage, l._cached_),
    ]
def is_stack_empty(*argl):
    return [
        (troop_slot_eq, stack_storage, 0, 0),
    ]

extend_syntax(push_value)     # (push_value, <value>),
extend_syntax(pop_value)      # (pop_value, <destination>),
extend_syntax(peek_value)     # (peek_value, <destination>),
extend_syntax(is_stack_empty) # (is_stack_empty),


# Unlimited mission timers (NEVER use reset_mission_timer_c !!!)

def start_mission_timer(timer_index, *argl):
    return [
        (store_mission_timer_c_msec, l._cached_),
        (troop_set_slot, timers_storage, timer_index, l._cached_),
    ]
def store_mission_timer(destination, timer_index, *argl):
    return [
        (store_mission_timer_c_msec, destination),
        (troop_get_slot, l._cached_, timers_storage, timer_index),
        (val_sub, destination, l._cached_),
    ]

extend_syntax(start_mission_timer) # (start_mission_timer, <timer_index>),
extend_syntax(store_mission_timer) # (store_mission_timer, <destination>, <timer_index>),


# Useful operations

def get_fixed_point_multiplier(destination, *argl):
    return [
        (assign, destination, 1),
        (convert_to_fixed_point, destination),
    ]

def position_set_coordinates(position, x, y, z):
    return [
        (position_set_x, position, x),
        (position_set_y, position, y),
        (position_set_z, position, z),
    ]

def troop_set_attribute(troop, attribute, value):
    return [
        (store_attribute_level, l._cached_, troop, attribute),
        (store_sub, l._cached_, value, l._cached_),
        (troop_raise_attribute, troop, attribute, l._cached_),
    ]

def troop_set_skill(troop, skill, value):
    return [
        (store_skill_level, l._cached_, skill, troop),
        (store_sub, l._cached_, value, l._cached_),
        (troop_raise_skill, troop, skill, l._cached_),
    ]

extend_syntax(get_fixed_point_multiplier) # (get_fixed_point_multiplier, <destination>),
extend_syntax(position_set_coordinates)   # (position_set_coordinates, <pos>, <x_fixed_point>, <y_fixed_point>, <z_fixed_point>),
extend_syntax(troop_set_attribute)
extend_syntax(troop_set_skill)
 
Status
Not open for further replies.
Back
Top Bottom