PDA

Click to See Complete Forum and Search --> : Adding some numbers with flash problem, please help.



ziplockkitty
04-18-2002, 10:51 AM
Hey everyone, I am having trouble keeping track of how much gold the character has. I have a text box named gold, inside an MC named inventory. I have it set so you start out with 1000 gold. When you kill a cetain enemy you get 25 gold. I put this on the enemy:
if (this.hittest(_root.hero.sword)) {
gotoAndStop (2);
_root.inventory.gold = _root.inventory.gold+25;
}
For some reason, after you kill the dragon instead of adding the 25 to the original number it adds a 25 to the end of the number resulting in 100025 instead of 1025. I must be doing something wrong. Thanks.

bit-101
04-18-2002, 11:18 AM
values in txt boxes will always be strings. convert to a number before performing math on them:

number(valuefromtextbox)

ziplockkitty
04-18-2002, 11:43 AM
I dont understand, do you mean
if (this.hittest(_root.hero.sword)) {
gotoAndStop (2);
_root.inventory.gold = number(_root.inventory.gold)+25;
}
?

ziplockkitty
04-18-2002, 11:45 AM
It worked, thank you.

bit-101
04-18-2002, 11:59 AM
yup. that's what i meant.

ghicken
11-26-2008, 07:24 PM
Im having a similar problem, I have a text box labeled money and the text box is set to start with 100 and I want it to subtract 10 when it hits a ball ( what the script is on) i can only get it to subtract 1 when i put
onClipEvent (enterFrame) {
if (_root.map.char.hitTest (this)) {

_parent._parent.money--;
this._x = -700;
this._y = -700;
}
}
But when i put
onClipEvent (enterFrame) {
if (_root.map.char.hitTest (this)) {

_parent._parent.money-10;
this._x = -700;
this._y = -700;
}
}
It does not work.
I dont know what could be wrong. Thanks

StephenN
11-26-2008, 09:30 PM
_parent._parent.money--;

is the same as

_parent._parent.money = _parent._parent.money - 1;

so try

_parent._parent.money = _parent._parent.money - 10;

ghicken
11-27-2008, 12:54 AM
It worked fine. Thanks !

pseudobot
11-29-2008, 04:39 AM
^Or, to shorten it, you can write

_parent._parent.money -= 10;
:)