Page 1 of 1

[SOLVED]Comparing char* from gb.Keyboard()

PostPosted: Thu Jan 22, 2015 3:13 pm
by ajsb113
So I'm trying to implement a code input for my game Maruino and I'm having a bit of trouble comparing the strings that come out of the keyboard method. I would like to have support for the symbols as well, not just the letters. If anybody has ideas or knows how to do this, I'd like some help. :)

Re: Comparing char* from gb.Keyboard()

PostPosted: Thu Jan 22, 2015 4:06 pm
by rodot
Hey,

You can use the function strstr to check if one chain is contained into another. I changed the keyboard example for it to check if you entered a smiley face :

Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

char text[13] = "Default text";

void setup(){
  gb.begin();
  gb.titleScreen(F("Keyword example"));
  gb.keyboard(text, 13);
}

void loop(){
  if(gb.update()){
    gb.display.println(F("You wrote:"));
    gb.display.println(text);
   
    if(strstr(text,":)")){
      gb.display.println(F("Nice Smiley!"));
    }

    if(gb.buttons.pressed(BTN_C)){
      gb.titleScreen(F("Keyword example"));
      gb.keyboard(text, 13);
    }
  }
}


Concerning special characters, you can type them in your source code using the octal value of the character in an escape sequence ("\" followed by the octal value). Check the character table to find the code : first is the row number and second the column number. For example "\25\26\27" is the string "A button symbol", "B button symbol", "C button symbol".

Font5x7.png
Font5x7.png (4.32 KiB) Viewed 3301 times

Re: Comparing char* from gb.Keyboard()

PostPosted: Thu Jan 22, 2015 9:51 pm
by ajsb113
Thanks! I'll try that out. :D