Understanding the language, error messages, etc.
by ajsb113 » Thu Jan 22, 2015 3:13 pm
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.
Last edited by
ajsb113 on Fri Jan 23, 2015 3:24 pm, edited 1 time in total.
-
ajsb113
-
- Posts: 45
- Joined: Tue Jun 24, 2014 4:47 am
- Location: Illinois, United States
by rodot » Thu Jan 22, 2015 4:06 pm
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 (4.32 KiB) Viewed 3357 times
-
rodot
- Site Admin
-
- Posts: 1290
- Joined: Mon Nov 19, 2012 11:54 pm
- Location: France
-
by ajsb113 » Thu Jan 22, 2015 9:51 pm
Thanks! I'll try that out.
-
ajsb113
-
- Posts: 45
- Joined: Tue Jun 24, 2014 4:47 am
- Location: Illinois, United States
Return to Programming Questions
Who is online
Users browsing this forum: No registered users and 4 guests