Jump to content

Photo

Read ini file > assign variable values


45 replies to this topic

#46 Gwendolyne

Gwendolyne
  • Members
  • 216 posts
  • Gender:Male
  • Location:France

Posted 09 October 2018 - 12:51 AM

ALIEN, I polished my code to check if user variables fit to their scope.

 

ALWAYS BLOCK:

    OUTER_SPRINT configuration-default "%MOD_FOLDER%/1pp-config-default.ini" // default configuration file to read initial variable values
    OUTER_SPRINT configuration "%MOD_FOLDER%/1pp-config.ini" // user created file, not included inside mod archive. If exists, it will overwrite variable values from 1pp-config-default file

    ACTION_IF FILE_EXISTS ~%configuration-default%~ THEN BEGIN
        PRINT "%configuration-default%"
        LAF GlobalVariableFromIni STR_VAR filename = "%configuration-default%" RET_ARRAY IniArray = GlobalIniArray END
    END

    ACTION_IF FILE_EXISTS ~%configuration%~ THEN BEGIN
        PRINT "%configuration%"
        LAF GlobalVariableFromIni STR_VAR filename = "%configuration%" RET_ARRAY IniArray = GlobalIniArray END
    END

    LAM ~GW_CHECK_CONFIG_VARIABLES~

    PRINT @3 /* ~LIST OF VARIABLES USED DURING NSTALLATION:
------------------------------------------
    1pp_fdwarf = %1pp_fdwarf%
    1pp_gui = %1pp_gui%
    1pp_updated_fonts = %1pp_updated_fonts%
    1pp_mixed_labels = %1pp_mixed_labels%
    1pp_agannazar_scorcher = %1pp_agannazar_scorcher%
    1pp_dispel_magic_effect = %1pp_dispel_magic_effect%
    1pp_hammers_icons = %1pp_hammers_icons%
    1pp_potions_icons = %1pp_potions_icons%
    1pp_iwd_cause_wounds_icons = %1pp_iwd_cause_wounds_icons%
    1pp_spells_conflict = %1pp_spells_conflict%
    1pp_shields_appearance = %1pp_shields_appearance%
    1pp_shields_scatter = %1pp_shields_scatter%
    1pp_helmets_appearance = %1pp_helmets_appearance%
    1pp_helmets_scatter = %1pp_helmets_scatter%
    1pp_helmets_compatibility = %1pp_helmets_compatibility%
    1pp_armours_appearance = %1pp_armours_appearance%
    1pp_armours_scatter = %1pp_armours_scatter%
    1pp_forced_item_colours = %1pp_forced_item_colours%
    1pp_shields_shadows = %1pp_shields_shadows%
    1pp_helmets_shadows = %1pp_helmets_shadows%
    1pp_gemlore = %1pp_gemlore%
    1pp_tutu_bg1_shields = %1pp_tutu_bg1_shields%
    1pp_tutu_bg1_helmets = %1pp_tutu_bg1_helmets%
    1pp_sleeper = %1pp_sleeper%
    1pp_colour_iwd = %1pp_colour_iwd%
    1pp_solar_weapons = %1pp_solar_weapons%~*/

and the new function GW_variables_check:

ACTION_CLEAR_ARRAY GW_variables_check
ACTION_DEFINE_ASSOCIATIVE_ARRAY GW_variables_check BEGIN
//  VARIABLE          VALUES : MAX  => DEFAULT
    fdwarf,                     2   => 2
    gui,                        2   => 1
    updated_fonts,              2   => 1
    mixed_labels,               2   => 1
    agannazar_scorcher,         2   => 2
    dispel_magic_effect,        2   => 1
    hammers_icons,              2   => 1
    potions_icons,              2   => 1
    iwd_cause_wounds_icons,     2   => 1
    spells_conflict,            2   => 1
    shields_appearance,         4   => 1
    shields_scatter,            2   => 1
    helmets_appearance,         4   => 1
    helmets_scatter,            2   => 1
    helmets_compatibility,      3   => 1
    armours_appearance,         4   => 1
    armours_scatter,            2   => 1
    forced_item_colours,        4   => 1
    shields_shadows,            2   => 2
    helmets_shadows,            2   => 2
    gemlore,                    2   => 1
    tutu_bg1_shields,           2   => 1
    tutu_bg1_helmets,           2   => 1
    sleeper,                    2   => 1
    forced_item_colours_iwd,    2   => 1
    solar_weapons,              2   => 1
END


DEFINE_ACTION_MACRO ~GW_CHECK_CONFIG_VARIABLES~
BEGIN

    ACTION_PHP_EACH GW_variables_check AS variable => default BEGIN
        ACTION_IF (VARIABLE_IS_SET $IniArray("1pp_%variable_0%")) BEGIN
            ACTION_IF (NOT(IS_AN_INT $IniArray("1pp_%variable_0%")) || ($IniArray("1pp_%variable_0%") > %variable_1% ) || ($IniArray("1pp_%variable_0%") < 1)) BEGIN
                OUTER_TEXT_SPRINT wrong_value $IniArray("1pp_%variable_0%")
                OUTER_TEXT_SPRINT $IniArray("1pp_%variable_0%") "%default%"
                OUTER_SET value = $IniArray("1pp_%variable_0%")
                PRINT @1 // ~Variable 1pp_%variable_0% value (%wrong_value%) does not match its scope and has been reset to its default value (%value%).~
            END ELSE BEGIN
                OUTER_SET value = $IniArray("1pp_%variable_0%")
            END
        END ELSE BEGIN
            OUTER_TEXT_SPRINT $IniArray("1pp_%variable_0%") "%default%"
            OUTER_SET value = $IniArray("1pp_%variable_0%")
            PRINT @2 // ~Variable 1pp_%variable_0% does not exist: it has been set to its default value (%value%).~
        END
        OUTER_SET EVAL "1pp_%variable_0%" = %value%
    END
    ACTION_CLEAR_ARRAY GW_variables_check

For my mod, I need to add a validity check for string variables.


CARPE DIEM...



In progress : Menace sur le Royaume de Diamant Éternel



Reply to this topic



  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users