Be a Supporter!

As2: Shared Object Help?

  • 414 Views
  • 8 Replies
New Topic Respond to this Topic
KirtTheGreat
KirtTheGreat
  • Member since: Aug. 11, 2009
  • Offline.
Forum Stats
Member
Level 07
Game Developer
As2: Shared Object Help? 2012-07-03 15:16:26 Reply

I created a shared object so that a level select menu unlocks when the game is completed and it doesn't reset if you reload the game. I was wondering how I should know if this is working. Does a shared object normally work when you publish the swf, or do I have to do something else to test it? Also, I wasn't sure what I was supposed to set the value of the shared object to once the game is actually completed.


ENGORGE!!!

BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to As2: Shared Object Help? 2012-07-03 15:20:55 Reply

It should work right away, and if you may need to delete the save on your computer if you want to keep testing it. It's better to build in SharedObjects early I think.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
KirtTheGreat
KirtTheGreat
  • Member since: Aug. 11, 2009
  • Offline.
Forum Stats
Member
Level 07
Game Developer
Response to As2: Shared Object Help? 2012-07-03 15:23:47 Reply

yeah I actually created the shared object on the very first frame of the game and then on the game complete screen I gave it data. I think my problem here must be that I had no idea what to put for the object's value. Is there a certain thing I need to make the value, like how a boolean can only be true or false?


ENGORGE!!!

BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to As2: Shared Object Help? 2012-07-03 15:49:43 Reply

Post what you've written.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
KirtTheGreat
KirtTheGreat
  • Member since: Aug. 11, 2009
  • Offline.
Forum Stats
Member
Level 07
Game Developer
Response to As2: Shared Object Help? 2012-07-03 16:08:02 Reply

On the first frame I have this to create the shared object:

GameComplete =SharedObject.getLocal("complete");

Then on the frame right before the menu I have this:

if(GameComplete.data.tname != undefined) {
gotoAndPlay("menu2")
} else {
play();
}

Finally, on the game complete screen I have this:

GameComplete.data.tname = "done";

I didn't know what to set the value to, but I'm pretty sure it shouldn't be "done" lol


ENGORGE!!!

BBS Signature
KirtTheGreat
KirtTheGreat
  • Member since: Aug. 11, 2009
  • Offline.
Forum Stats
Member
Level 07
Game Developer
Response to As2: Shared Object Help? 2012-07-03 16:09:46 Reply

Well I realized I had a typo in there when I pasted that code lol and it seems to be working fine now. Can the value of the shared object really be anything?


ENGORGE!!!

BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to As2: Shared Object Help? 2012-07-03 16:38:21 Reply

At 7/3/12 04:09 PM, KirtTheGreat wrote: Well I realized I had a typo in there when I pasted that code lol and it seems to be working fine now. Can the value of the shared object really be anything?

An object can contain most, if not all datatypes, not entirely sure, there might be some deep down ones that I don't know about. Like I'm not sure if you can put a function in it an expect it to work properly.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to As2: Shared Object Help? 2012-07-03 16:43:23 Reply

Flash automatically saves data while closing, but if you plan on saving and loading the data multiple times I'd suggest using the flush() function.

GameComplete.flush()


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
KirtTheGreat
KirtTheGreat
  • Member since: Aug. 11, 2009
  • Offline.
Forum Stats
Member
Level 07
Game Developer
Response to As2: Shared Object Help? 2012-07-03 16:54:49 Reply

Thanks a lot man everything's working great now. I think you along with a couple other people have answered every single one of my questions on these forums lol. Thank god Newgrounds has a really helpful community.


ENGORGE!!!

BBS Signature