Be a Supporter!

Score not working

  • 404 Views
  • 7 Replies
New Topic Respond to this Topic
ChilliDog
ChilliDog
  • Member since: Feb. 16, 2007
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Score not working 2007-06-13 16:28:52 Reply

Ok so here's what's going on. I have an item that you drag into a bag and when you do so it adds one to your score. Here's the code for the item(I'm pretty much a n00b at AS ):

on(release) {
this.stopDrag();
if(_root.bag.hitTest(this._x, this._y, true)) {
this.gotoAndStop("invis");
_global.playerScore = _global.playerScore + 1;
_root.scorebox.text = "Chickens: "+_global.playerScore;
}
else if(_root.bag.hitTest(this._x, this._y, false)) {
this.gotoAndPlay(1);
}
}

So basically when the item "goes into" the bag the global score variable is updated to whatever it currently is, plus one and the value in the dynamic text box is updated to display the global variable which has just been changed. Again, I'm pretty new to AS so I realize I could be way off with this code.

When I run the game and drag the items into the bag, rather than add one to the score it adds the number 1. So, after adding three items my score is 0111, instead of 3.

I'm not sure exactly what I need to fix so any help is greatly appreciated. Thanks!


AS: Main

Don't read this sentence.

Paradox
Paradox
  • Member since: Jan. 28, 2006
  • Offline.
Forum Stats
Member
Level 29
Blank Slate
Response to Score not working 2007-06-13 16:29:35 Reply

Fixed:

on(release) {
this.stopDrag();
if(_root.bag.hitTest(this._x, this._y, true)) {
this.gotoAndStop("invis");
_global.playerScore = _global.playerScore + 1;
_root.scorebox.text = "Chickens: "+_global.playerScore;
}
else if(_root.bag.hitTest(this._x, this._y, false)) {
this.gotoAndPlay(1);
}
}

ChilliDog
ChilliDog
  • Member since: Feb. 16, 2007
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Score not working 2007-06-13 16:34:27 Reply

I'm pretty sure that's the exact code I posted..Did you change anything?
I tested it just to see and I'm still getting the same problem.

The score starts off at 0
You add one item and it's 01
you add another and it's 011
you add a third and it's 0111


AS: Main

Don't read this sentence.

Paradox
Paradox
  • Member since: Jan. 28, 2006
  • Offline.
Forum Stats
Member
Level 29
Blank Slate
Response to Score not working 2007-06-13 16:35:12 Reply

At 6/13/07 04:34 PM, ChilliDog wrote: Did you change anything?

nah.

ChilliDog
ChilliDog
  • Member since: Feb. 16, 2007
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Score not working 2007-06-13 16:36:18 Reply

Forgot to mention, when the game starts I have this code:

_global.playerScore = "0";
_root.scorebox.text = "Chickens: "+_global.playerScore;

If that changes anything...


AS: Main

Don't read this sentence.

Amazing-Hazon
Amazing-Hazon
  • Member since: May. 31, 2006
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to Score not working 2007-06-13 16:53:52 Reply

It should work if you change

_global.playerScore = "0";

to

_global.playerScore = 0;

ChilliDog
ChilliDog
  • Member since: Feb. 16, 2007
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to Score not working 2007-06-13 16:57:13 Reply

Wow...I AM an idiot.
I tried putting () and "" around the +1 part of it but had totally forgot about that.
I guess I just put those "" in there out of habit?
Anyway, thanks a lot.

:I feel like a moron


AS: Main

Don't read this sentence.

FatalFuryX
FatalFuryX
  • Member since: Jun. 29, 2006
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Score not working 2007-06-13 17:05:24 Reply

_global.playerScore = 0

That should fix the problem. If you surround the 0 with "" than it thinks it is a string. Without "" it is a number.