Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a flash game in which i have a variable levelState that describes the current level in which user has entered I am using SharedObject to save the progress but it does not do so first i declred a clas level variable

private var levelState:Number = 1;
private var mySaveData:SharedObject = SharedObject.getLocal("levelSave");

in the Main function i am checking if it is a first run of the game like below

if (mySaveData.data.levelsComplete == null)
    {
        mySaveData.data.levelsComplete = 1;
    }

and in a function where the winning condition is checked so that levelState could be increased i am usin this sharedobject to hold the value of levelState

if (/*winniing condition*/)
    levelState++;
    mySaveData.data.levelsComplete = levelState;
    mySaveData.flush();
    setNewLevel(levelState);
}

but when i play the game clear a level and again run the game it does not start from that level it starts from beginning.

share|improve this question

1 Answer 1

Solution Actually in the main function i have to assign the levelState the value from the ShredObject . In the first part of the above code i added some lines like this

if (mySaveData.data.levelsComplete == null)
{
    mySaveData.data.levelsComplete = 1;
} else {
   levelState = mySaveData.data.levelsComplete
}

That else part i was missing

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.