Space as a <char> via XML

Hi all,
I am trying to pass the spacebar value as a char via xml with ofXML.
here is the OF code

if(settings.exists("//playButton")) {
        playKey = settings.getValue<char>("//playButton");
    } else {
        playKey = ' ';

here is the XML code

<?xml version="1.0" encoding="UTF-8"?>
<playButton>' '</playButton>

things I tried already instead of ’ ’ (even if they don’t make sense…)
& # 32; (without spaces between characters)
" "
one thing that works is using <int> 32 instead of <char>.
This will work but only with the space. As I want to have flexibility to choose any other character I’d like to stick to <char>
I am a bit stuck and I could really use some help on this… maybe it’s easy?


what about just:

<playButton> </playButton>

if that doesn’t work then:

<playButton><![CDATA[ ]]></playButton>

should, note the space between the inner most brackets in the cdata version.

Hi @arturo thanks for replying.
I tried both and none works… I c’d out the val just to understand what was going on and I get a flipped question mark as a cout…

cout << ofToString(settings.getValue<char>("//playButton")) <<endl;
I am keep on looking in this direction, in the meanwhile, if you have any other idea I am glad to try it out.
I am wondering if the problem is with my code and I don’t see it…?
I am posting the full code

    //XML settings
        //load the xml
        //check if it exists, then set the commands
        if(settings.exists("//sequence")) {
            counter	= settings.getValue<int>("//sequence");
        } else{
            counter = MAX_SEQUENCE;    

        if(settings.exists("//leftButton")) {
            leftKey = settings.getValue<char>("//leftButton");
        } else{
            leftKey = 'a';

        if(settings.exists("//rightButton")) {
            rightKey = settings.getValue<char>("//rightButton");
        } else {
            rightKey = 'l';

        if(settings.exists("//playButton")) {
            playKey = settings.getValue<char>("//playButton");
            cout << ofToString(settings.getValue<char>("//playButton")) <<endl;
        } else {
            playKey = ' ';

        if(settings.exists("//playAgainButton")) {
            playAgainKey = settings.getValue<char>("//playAgainButton");
        } else {
            playAgainKey = 'r';

and then the xml

<?xml version="1.0" encoding="UTF-8"?>

    <playButton> <![CDATA[ ]]> </playButton>

can you remove the extra spaces in playButton? also are you using OF 0.9.8 or the nighly builds / master

using this version of_v0.9.8_osx_release
removed spaces… nothing changed

what do you get if you get the value as a string?

I set playKey as a string and in keyReleased I’ve put

if (key == ofToChar(playKey)) {

//XML part

 if(settings.exists("//playButton")) {
        playKey = settings.getValue<string>("//playButton");
        cout << ofToString(settings.getValue<string>("//playButton")) <<endl;
    } else {
        playKey = ' ';

and then tried the same combination in the XML file

’ ’
just space
" "
& # 32 ;

sitll no luck.
Is this what you meant right?

an update is that
&#121; = char y

same thing with
<playButton>&#32;</playButton> doesn’t.
32 is space…
not sure what this means but it sounds like a lead…

what do you get with:


i mean what are the contents of the returned string?

if I use <![CDATA[ ]]>
I get nothing in the consolle, which may also be a space.
but what I found out now is that if I press Ctrl+ spacebar, it works…
I feel like we are almost there…

can you check the string programatically something like:

auto str = settings.getValue<string>("//playButton");
for(auto & c: str){
    cout << (int)c << endl;

gives back 32

so that’s a space already, not sure why it won’t work with char instead of string but perhaps you can just use string and get the first char out of it unless it’s empty like;

    playButton = settings.getValue<string>("//playButton")[0];

Not sure I understand either.
It works the same way even just getting the [0]
It works on a ctrl+spacebar but not just spacebar, even if the out value is 32.
I’ll leave it like this for now, I’ll come back to it later.
if you come up with some idea, please post it and I’ll do the same.

Thanks a lot for your help!

Cheers :slight_smile:

not sure what you mean, if the first character is a 32 then you are already getting a space no?

if I call playButton = settings.getValue<string>("//playButton")[0];
or playButton = settings.getValue<string>("//playButton");

in both cases I get as cout 32

however in both cases the app doesn’t behave as it’s receiving 32 as, when I press spacebar, I get nothing.
It behaves correctly if I press ctrl+spacebar

if you change your original code with:

        if(settings.exists("//playButton") && !settings.getValue<string>("//playButton").empty()) {
            playKey = settings.getValue<string>("//playButton")[0];
        } else {
            playKey = ' ';

keeping playKey as a char, doesn’t it work?

nope :confused:
same behaviour… it works only if I press ctrl+spacebar.
Let me see if I can try on another machine… or I can plug an external keyboard

it seems like there might be something else wrong then, if the string’s first character is 32 that must work

I’ve no idea to be honest.
As I said, the test with another char y was working. I guess it’s a problem with this specific char 32… maybe?
I;m just guessing…
if there was something wrong with the code that wouldn’t work with other chars I think…
I also tried on another machine and keyboard… but same behaviour.
I don’t want to drive you crazy… I want to wait and see if I can come up with some idea…
there was a post on this forum that I read before, Crash on startup (_glfwPlatformGetVideoMode)
do you think that could be somehow related?