Sat Mar 07, 2015 1:08 am
const char* newTileStrings[] PROGMEM = {"Good. You merged an 8 tile.", "Great. You merged a 16 tile.", "Awesome! You merged a 32 tile.",
"Sweet! You merged a 64 tile.", "Getting bigger... You merged a 128 tile.", "Even bigger... You merged a 256 tile.",
"Nearly there... You merged a 512 tile.", "Just one more... You merged a 1024 tile.", "You are a winner! You merged a 2048 tile.",
"Next step up! You merged a 4096 tile.", "You're getting good! You merged a 8192 tile.", "You gonna keep playing? You merged a 16384 tile.",
"This is getting serious... You merged a 32768 tile.", "You are a 2048 god! You merged a 65536 tile.", "INSANE!!! You merged a 131072 tile."
};
void PopupMessage() {
int MaxTile = 0;
for( int x; x < 16; x++ ) {
MaxTile = max(Board2048[x],MaxTile);
}
for( int x; x < 16; x++ ) {
if (Board2048Old[x] == MaxTile) MaxTile = 0;
}
if (MaxTile >= 3) {
gb.popup(newTileStrings[MaxTile-3],100);
}
}
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI/SPI.h:17,
from Gamebuino2048.ino:1:
Gamebuino2048.ino:18:30: error: variable 'newTileStrings' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
Gamebuino2048.ino: In function 'void PopupMessage()':
Gamebuino2048.ino:626:43: error: no matching function for call to 'Gamebuino::popup(const char*&, int)'
Gamebuino2048.ino:626:43: note: candidate is:
In file included from Gamebuino2048.ino:2:0:
C:\Users\Owner\Documents\Arduino\libraries\Gamebuino/Gamebuino.h:64:10: note: void Gamebuino::popup(const __FlashStringHelper*, uint8_t)
void popup(const __FlashStringHelper* text, uint8_t duration);
^
C:\Users\Owner\Documents\Arduino\libraries\Gamebuino/Gamebuino.h:64:10: note: no known conversion for argument 1 from 'const char*' to 'const __FlashStringHelper*'
Error compiling.
Sat Mar 07, 2015 4:48 am
const char msg1[] PROGMEM = "Good. You merged an 8 tile.";
const char msg2[] PROGMEM = "Great. You merged a 16 tile.";
const char msg3[] PROGMEM = "Awesome! You merged a 32 tile.";
// etc
const char* const newTileStrings[] PROGMEM = { msg1, msg2, msg3 /* etc */ };
// then this:
gb.popup((const __FlashStringHelper*)newTileStrings[msgNum],100);
Sat Mar 07, 2015 6:34 pm
Myndale wrote:There are actually two kinds of arrays here, the string themselves (array of char) and the table that points to them. You're declaring the table in PROGMEM but it's still ambiguous to the compiler where you want the strings themselves. Try this instead:
- Code:
const char msg1[] PROGMEM = "Good. You merged an 8 tile.";
const char msg2[] PROGMEM = "Great. You merged a 16 tile.";
const char msg3[] PROGMEM = "Awesome! You merged a 32 tile.";
// etc
const char* const newTileStrings[] PROGMEM = { msg1, msg2, msg3 /* etc */ };
// then this:
gb.popup((const __FlashStringHelper*)newTileStrings[msgNum],100);
Sat Mar 07, 2015 9:18 pm
JWinslow23 wrote:That works fine if msgNum is simply a number, but for variables, it seems not to work. It just displays garbage. Any fix for that?
gb.popup((const __FlashStringHelper*)pgm_read_word(&newTileStrings[msgNum]),100);
Sat Mar 07, 2015 10:58 pm