Fixed handling of force_valid in variable.cpp...
...to correctly account for the difference between created array and plain variables.
This commit is contained in:
parent
28e92236ca
commit
235760192b
2 changed files with 19 additions and 6 deletions
|
@ -1317,6 +1317,7 @@ WML_HANDLER_FUNCTION(move_units_fake, /*event_info*/, cfg)
|
|||
|
||||
WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
||||
{
|
||||
static const config::t_token z_empty("", false);
|
||||
static const config::t_token z_name("name", false);
|
||||
static const config::t_token z_literal("literal", false);
|
||||
static const config::t_token z_value("value", false);
|
||||
|
@ -1344,6 +1345,9 @@ WML_HANDLER_FUNCTION(set_variable, /*event_info*/, cfg)
|
|||
game_state *state_of_game = resources::state_of_game;
|
||||
|
||||
const config::t_token & name = cfg[z_name];
|
||||
if(name == z_empty){
|
||||
throw config::error("Mandatory WML variable name is empty \"\"."); }
|
||||
|
||||
config::attribute_value &var = state_of_game->get_variable(name);
|
||||
|
||||
config::attribute_value const & literal = cfg.get_config()[z_literal]; // no $var substitution
|
||||
|
|
|
@ -755,11 +755,14 @@ void variable_info::init(const config::t_token& varname, bool force_valid) {
|
|||
throw game::wml_syntax_error(tokens, i - tokens.begin() , _("the WML array index is invalid. Use varname[0].length to check for the existence of an array element.") );
|
||||
} //else return length 0 for non-existent WML array (handled below)
|
||||
}
|
||||
vars = &vars->child(i->token, inner_index);
|
||||
|
||||
} else {
|
||||
if( i == second_last_token && last_token->token == z_length){
|
||||
switch(vartype) {
|
||||
case variable_info::TYPE_ARRAY:
|
||||
case variable_info::TYPE_CONTAINER:
|
||||
is_valid_ = force_valid || repos->temporaries_.child(varname);
|
||||
WRN_NG << _("variable_info: using reserved WML variable as wrong type, ") << varname << std::endl;
|
||||
is_valid_ = force_valid || repos->temporaries_.child(varname);
|
||||
throw game::wml_syntax_error(tokens, i - tokens.begin()
|
||||
|
@ -776,13 +779,19 @@ void variable_info::init(const config::t_token& varname, bool force_valid) {
|
|||
vars = &repos->temporaries_;
|
||||
return;
|
||||
}
|
||||
}
|
||||
vars = &vars->child(i->token, inner_index);
|
||||
|
||||
config *ovars(vars);
|
||||
vars = &vars->child(i->token, inner_index);
|
||||
|
||||
//todo fix the config operator bool and change (vars == NULL)to !vars
|
||||
if(vars == NULL){
|
||||
if(force_valid) {
|
||||
vars = &ovars->add_child(i->token); }
|
||||
else {
|
||||
is_valid_ = false;
|
||||
return; } }
|
||||
}
|
||||
|
||||
//todo fix the config operator bool and change (vars == NULL)to !vars
|
||||
if(!force_valid && vars == NULL){
|
||||
is_valid_ = false;
|
||||
return; }
|
||||
++i;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue