FlxSave problems on android

76 views
Skip to first unread message

JustinG126

unread,
Apr 6, 2016, 9:04:05 AM4/6/16
to HaxeFlixel


Hello,

I started recently with HaxeFlixel, for my project I need a simple highscore implementation. I got this to work on my pc, but when I try to run a debug or release on my android mobile it doesn't work.

Im using in the menustate create function:

highSave = new FlxSave();
highSave.bind("Highscore");
var tempScore : Int;
if (highSave.data.scoreArray == null){
tempScore = 0;
} else {
tempScore = highSave.data.scoreArray[0];
}
scoreText = new FlxText(100, 100, 500, "HighScore: " + tempScore, 30);
scoreText.color = (0x0B3B17);
add(scoreText);

then in the playstate when the this state is finished and is supposed to return to menustate I use:

if (MenuState.highSave.data.scoreArray != null && score > MenuState.highSave.data.tempHigh[0]) {
MenuState.highSave.data.scoreArray = new Array<Int>();
MenuState.highSave.data.scoreArray.push(score);
//MenuState.highSave.flush();
MenuState.highSave.close();
}
FlxG.switchState(new MenuState());

As mentioned earlier this works on my pc, but on my android it keeps always showing "HighScore: 0".
I suspect it has to do with internal storage permissions, I added permissions to write and read on external storage in the project.xml and it also shows that the app has those permissions. I have tried to move the app to the external storage but this is not supported on my phone. And I see no files being created on external storage.

I hope someone can help me fix this problem.

Sam Bellman

unread,
Apr 7, 2016, 10:19:22 AM4/7/16
to HaxeFlixel
When trying to save to with android i have occasionally found it picky when trying to save non primitive types. It could be worth trying to serialize your data before saving then unserialise it when reading it.

Something like this:
var serializer:Serializer = new Serializer();
serializer.serialize(highScoresArray);
highScoresSave.data.highScoresArray= serializer.toString();
highScoresSave.flush();
then
var unserializer:Unserializer = new Unserializer(highScoresSave.data.highScoresArray);
highScoresArray = unserializer.unserialize();

Claudio Ficara

unread,
Apr 7, 2016, 3:50:18 PM4/7/16
to HaxeFlixel
Use data.flush() . I experienced this before, and using flush for some reason makes it work on cpp targets (android, windows)

JustinG126

unread,
Apr 8, 2016, 6:03:41 PM4/8/16
to HaxeFlixel
Okay I fixed the problem, Thanks for the reactions but this was not the problem. The problem was me being stupid -.-

The line: if (MenuState.highSave.data.scoreArray != null && score > MenuState.highSave.data.tempHigh[0]) {
While testing on my pc I created a save file for this, just with FlxSave, later I added this line above.
When testing on my mobile there was no save file yet so it would always return false on this statement -> never saving the data.
So it would always make tempScore = 0.

Thanks again for the reactions :)
Reply all
Reply to author
Forward
0 new messages