Xmlparam.findparam fails if the param Str name contains:
spaces
/
comma (,)
@
Haven't tested the full range, other things probably break it as well.
In 1.0 you could have all characters except spaces, now in 2.0 more things seem to bug out Xmlparam.findparam. My param names are the names of my Input.name so things like "Move Left" "Crouch,Fly Down", "Lightening Storm" etc..
The names of my params contain spaces / , etc so I need to use the following when I save or load from the XML file.
Seems like a bug because @ / , space etc are allowed to be Xml param names per the xml spec,only < > & require escape sequences.
Here is the workaround I use for my input bind loading:
Code:
Str xml_string_space_remove(Str string)
{
return Replace(Replace(Replace(string, ',', ""), ' ', ""), '/', "");
}
/******************************************************************************/
void load_binds(Str name)
{
defaultkeybinds(); // reset them so when we switch chars unbound things don't carry over
Str filename = S+ name + "_bindings.txt";
XmlData data; data .load (filename);
//inputbinds.clear();
REPA(inputbinds)
{
if(XmlNode *node=data .findNode ("inputbinds"))
if(XmlParam *param=node.findParam(xml_string_space_remove(inputbinds[i].input.name)))
//if(XmlParam *param=node.findParam(inputbinds[i].input.name))
{
if(param.value.is())
{
CM.New(S+"Loaded: "+xml_string_space_remove(inputbinds[i].input.name));
Byte btnbyte = TextInt(param.value); //CM.New(S+ "byte "+ btnbyte+ " value "+ email.value );
if(btnbyte != 199)inputbinds[i].input.b[0].type = INPUT_KEYBOARD; // 199 is what all the INPUT_NONE things seem to save as
inputbinds[i].input.b[0].button = btnbyte;
}
} else{CM.New(S+"Xmlparam not found: "+xml_string_space_remove(inputbinds[i].input.name)); }
}
bindswindow.build(); // rebuild the binds window to account for the updated 'inputbinds' container
}
/******************************************************************************/
void save_binds(Str name)
{
Str filename = S+ name + "_bindings.txt";
FDel(filename);
XmlData data; data .load(filename);
REPA(inputbinds)
{
XmlNode &node=data .getNode ("inputbinds");
XmlParam ¶m=node.getParam(xml_string_space_remove(inputbinds[i].input.name)); // the storage parameter is the name of the bind like "Move Forward" or "Lightening Storm"
// XmlParam ¶m=node.getParam(inputbinds[i].input.name);
param.value=inputbinds[i].input.b[0].button;
}
data.save(filename);
}