Author Topic: FlxSave only works locally [Fixed!]  (Read 2333 times)

Kytin

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
FlxSave only works locally [Fixed!]
« on: Sun, Dec 4, 2011 »
I recently got my game prototype to the stage where I'm happy to start showing it around. Unfortunately, after I upload it to a hosting site, I find that it no longer saves and loads the way it does when I run the swf from my computer. I'm using FlxSave, and as far as I can tell, I have done everything correctly.

I figure I'm probably just overlooking some simple thing, but I really haven't been able to determine what. It's quite frustrating as I can't use the debugger to see what all my code is doing.


Anyway, here's the relevant code:
Code: [Select]
package 
{
/**
* ...
* @author Stephen Ashby
*/
import org.flixel.*;
import flash.utils.*;
 
public class PlayState extends FlxState
{
public var level:BaseLevel;
//public var player:Player;

private static var _save:FlxSave; //The FlxSave instance
private static var canUseSave:Boolean = false; //Did bind() work? Do we have a valid SharedObject?

public static function initSaves():void
{
_save = new FlxSave();
canUseSave = _save.bind("savegame");

Registry.initializeEventFlags();

//if the save file has never been used before, create the eventFlags array
if (_save.data.eventFlags == null)
{
_save.data.eventFlags = new Array();
for each(var f:Boolean in Registry.eventFlags)
{
(_save.data.boxPositions as Array).push(f);
}
}
}

override public function create():void
{
if ( canUseSave == false)
trace("Failed to initialize savestate! Your game cannot be saved!");

if (Registry.level == null && Registry.nextLevel == null)
Registry.setLevel(DemoLevel1);

if (Registry.player == null)
Registry.player = new Player(34.000, 448.000);


FlxG.worldBounds = new FlxRect(0, 0, 80 * 16, 30 * 16);
}

public function PlayState():void
{
super();
initSaves();
}

override public function update():void
{
super.update();

if (FlxG.keys.justPressed("S"))
{
Registry.saveTheGame = true;
}

if (FlxG.keys.justPressed("L"))
{
loadGame();
}

if (FlxG.keys.justPressed("D"))
{
//do debug stuff
level.alive = true;
}


if (Registry.saveTheGame)
{
Registry.saveTheGame = false;
saveGame();
}
//if Registry.setLevel() has been called, but not acted on
//change the level to the new one
if (Registry.nextLevel != null)
{
levelChange();
}

if (FlxG.keys.justPressed("ESCAPE"))
{
Registry.gotoMainMenu = true;
}

if (Registry.gotoMainMenu)
{
  Registry.gotoMainMenu = false;


clearPlayer();
clearLevel();
FlxG.switchState(new MenuState());
}
}

//clears the currently loaded player character
public function clearPlayer():void
{
//destroy current player character, if there is one
if (Registry.player != null)
{
Registry.player.destroy();
Registry.player = null;
}
}

//clears the currently loaded level
public function clearLevel():void
{
//destroy current level, if there is one
if (level != null)
{ level.destroy(); }
remove(level);
Registry.level = null;

}

private function levelChange():void
{
//clear the current level
clearLevel();

//load new level
level = new Registry.nextLevel();
level.addPlayer();
add(level);
Registry.level = level;

Registry.currentLevel = Registry.nextLevel;
Registry.nextLevel = null;
}

private function saveGame():void
{

if (canUseSave)
{
_save.data.player.x = Registry.player.x;
_save.data.player.y = Registry.player.y;
_save.data.player.maxHealth = Registry.player.maxHealth;
_save.data.player.maxStamina = Registry.player.maxStamina;
var levelName:String = flash.utils.getQualifiedClassName( Registry.currentLevel );
_save.data.level = levelName;

var counter:uint = 0;
for each(var f:Boolean in Registry.eventFlags)
{
_save.data.eventFlags[counter] = f;
counter++;
}
}
else
{
trace("Savestate was not initialized. Your game cannot save.");
}
}

public function loadGame():void
{
clearPlayer();
clearLevel();

if (canUseSave && _save.data.player == null)
{
//if there is no saved game, start a new game
Registry.player = new Player(304.000, 202.000);
Registry.setLevel(Level2);
}
else if(canUseSave && _save.data.player != null)
{
//load the game properly
Registry.player = new Player(_save.data.player.x, _save.data.player.y, _save.data.player.maxHealth, _save.data.player.maxStamina);
Registry.setLevel(flash.utils.getDefinitionByName( _save.data.level ) as Class);


for (var i:uint; i < Registry.eventFlags.length; i++ )
{
Registry.eventFlags[i] = _save.data.eventFlags[i];

}
}
else
{
//if the save file does not load (corrupted?)...
trace("Savestate was not initialized. Your game cannot load.");
//... start a new game
Registry.player = new Player(304.000, 202.000);
Registry.setLevel(Level2);
}
}
}

}

EDIT: fixed a bug that was unrelated.
Also, a link to the swf: http://megaswf.com/serve/1385343/



After looking at things a bit closer, it appears that the FlxSave is failing to bind. Would this be due to my local flash setting, and if so, what do I need to change?




« Last Edit: Tue, Dec 6, 2011 by Kytin »
I have seen the future. You will not.

Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
Re: FlxSave only works locally
« Reply #1 on: Sun, Dec 4, 2011 »
Try right clicking the uploaded version, going to settings, and making sure your local storage options are set to allow enough space for the save to fit. Also make sure when you save you aren't creating a new one every time and using up more space than needed.

Kytin

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: FlxSave only works locally
« Reply #2 on: Mon, Dec 5, 2011 »
I changed my settings to allow unlimited storage space and it made no difference. I also checked where the sharedobjects were being saved, and there was only one, even after several save/load attempts.
I have seen the future. You will not.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: FlxSave only works locally
« Reply #3 on: Mon, Dec 5, 2011 »
On Windows Flash settings for this are now stored in the Control Panel. Go in there, search for Flash, and check you've got space / etc.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Kytin

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: FlxSave only works locally
« Reply #4 on: Mon, Dec 5, 2011 »
Ok, I checked flash in the control panel. It was already set to allow flash player to store data on my computer. I deleted the data from a few things I don't need anymore, and checked my uploaded swf again. I still have the same problem.
I have seen the future. You will not.

Kytin

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: FlxSave only works locally
« Reply #5 on: Tue, Dec 6, 2011 »
Seems I made a mistake earlier. The FlxSave is successfully binding (or at least returning true when it binds), but when I go to load a game it finds that the save.data is null.
I have seen the future. You will not.

Kytin

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: FlxSave only works locally [Fixed!]
« Reply #6 on: Tue, Dec 6, 2011 »
Fixed! Turns out that the problem was using containers for the variables I was saving (i.e I was saving player data as _save.data.player.x rather than as _save.data.playerX). Still don't know why it worked on my computer but not online.
I have seen the future. You will not.