AS2 SharedObject help?

Subscribe to AS2 SharedObject help? 6 posts

avatar for BritishGuile BritishGuile 40 posts
Flag Post

Hi, I’ve never used shared objects before and I’m running into some trouble which I hope somebody can help me with. The code below is on a movie clip and when the player wins the game if the score they achieved is their highest I want the game to save it and hold that value as the “bestscore”. All that I can get from in when I try to display the best score in a dynamic text box is “undefined”.Can anybody advise or do I need to go into more detail?

onClipEvent (load) {
	saveData = SharedObject.getLocal("SaveFileName");

	if (saveData.data.exists == 1)
	{
		bestscore = saveData.data.bestscore;
	}
	else
	{
		bestscore = 0;
		saveData.data.bestscore = bestscore;
		saveData.data.exists = 1;
		saveData.flush();
	}


}
onClipEvent (enterFrame) {

bestscore = saveData.data.bestscore;

	if (_root.player.win)
	{
		if (_root.player.score >= bestscore)
		{
			saveData.data.bestscore = _root.player.scorescore;
			saveData.flush();
		}
	}

}
 
avatar for saybox saybox 2665 posts
Flag Post
Originally posted by BritishGuile:
{
saveData.data.bestscore = _root.player.scorescore;
saveData.flush();
}
}

That line is your problem – you have a typo in your variable name :)

 
avatar for BritishGuile BritishGuile 40 posts
Flag Post

Bless you. I can’t believe I missed such an obvious mistake i have been try to solve the problem for ages now.

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by BritishGuile:

Bless you. I can’t believe I missed such an obvious mistake i have been try to solve the problem for ages now.

And if you were using AS3, it’d have thrown a compile error. ;)

 
avatar for saybox saybox 2665 posts
Flag Post
Originally posted by BritishGuile:
I can’t believe I missed such an obvious mistake

You’re welcome :) I make that sort of mistake a lot, partly because my mouse is faulty and messes up doubleclicks :D

 
avatar for Draco18s Draco18s 6860 posts
Flag Post
Originally posted by saybox:
Originally posted by BritishGuile:
I can’t believe I missed such an obvious mistake

You’re welcome :) I make that sort of mistake a lot, partly because my mouse is faulty and messes up doubleclicks :D

At least it isn’t MonoDevelop where if you’re not working in C#, it forgets how to be a text editor. >..>

Example:
Clipboard: someobject.someproperty
Code that needs above statement: somevar = x + 9;
Paste: somevar = x + 9 + someobject.someproperty;;

Note the extra semicolon. If I had pasted at the front, instead…(and then added the + )

Paste: somevar = someobject.somepropertyx + x + 9;

Now it’s got an extra x.

It’s REALLY annoying. And I checked, if you have a C# file open it doesn’t do it.