-
20x6
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.
-
values in txt boxes will always be strings. convert to a number before performing math on them:
number(valuefromtextbox)
-
20x6
I dont understand, do you mean
if (this.hittest(_root.hero.sword)) {
gotoAndStop (2);
_root.inventory.gold = number(_root.inventory.gold)+25;
}
?
-
20x6
-
yup. that's what i meant.
-
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
-
_parent._parent.money--;
is the same as
_parent._parent.money = _parent._parent.money - 1;
so try
_parent._parent.money = _parent._parent.money - 10;
-
-
Intermediate Game Dev
^Or, to shorten it, you can write
PHP Code:
_parent._parent.money -= 10;
Needs an update...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|