Forums

ForumsProgramming Forum

Saving Local Data AS3

Posted Mar 29, '08 at 5:17pm

macco

macco

19 posts

I would like to make a counter to look how many times someone visited my game.

This is my Code:

//Actionscript 3.0

var counter:Number
var myLocalData:SharedObject = SharedObject.getLocal("mygamedata");

myLocalData.data.gameinfo = counter
myLocalData.flush()

if (myLocalData.data.gameinfo != undefined) {
counter += 1
} else {
counter = 1
}

trace("This is your "+myLocalData.data.gameinfo + ". visit.");

Now. it always says: "This is your NaN visit."
Why is that? Is there any way to make a counter like that?

macco

 

Posted Mar 29, '08 at 6:18pm

Gimgak

Gimgak

310 posts

I'd say a better idea would be to put the counter on the .html file it's gonna be shown, or use newgrounds since they have a counter too

 

Posted Mar 29, '08 at 7:11pm

dank

dank

1,043 posts

Knight

You never assigned a number to counter. Therefor when you add 1 to null, you get Not a Number.

 

Posted Mar 29, '08 at 7:21pm

macco

macco

19 posts

i know i get no Number cause i haven't assigned it to anything.

But if i tell it to be 1. it will always tell me this is my first visit when i run my code.

nah, im not using newgrounds

 

Posted Mar 29, '08 at 10:48pm

Gimgak

Gimgak

310 posts

well, the truth is that every game site you submit it to it should have a counter. Just use a html counter

 

Posted Mar 31, '08 at 6:27am

macco

macco

19 posts

Found out how to do it,
I have to check it if it's NaN first.

 
Reply to Saving Local Data AS3

You must be logged in to post a reply!