ForumsProgramming ForumSaving Local Data AS3

5 3905
macco
offline
macco
19 posts
50

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

  • 5 Replies
Gimgak
offline
Gimgak
296 posts
85

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

dank
offline
dank
993 posts
960

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

macco
offline
macco
19 posts
50

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

Gimgak
offline
Gimgak
296 posts
85

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

macco
offline
macco
19 posts
50

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

Showing 1-5 of 5