A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Adding some numbers with flash problem, please help.

  1. #1
    20x6 ziplockkitty's Avatar
    Join Date
    Dec 2001
    Location
    Connecticut!!!
    Posts
    697
    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.

  2. #2
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    values in txt boxes will always be strings. convert to a number before performing math on them:

    number(valuefromtextbox)

  3. #3
    20x6 ziplockkitty's Avatar
    Join Date
    Dec 2001
    Location
    Connecticut!!!
    Posts
    697
    I dont understand, do you mean
    if (this.hittest(_root.hero.sword)) {
    gotoAndStop (2);
    _root.inventory.gold = number(_root.inventory.gold)+25;
    }
    ?

  4. #4
    20x6 ziplockkitty's Avatar
    Join Date
    Dec 2001
    Location
    Connecticut!!!
    Posts
    697
    It worked, thank you.

  5. #5
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    yup. that's what i meant.

  6. #6
    Junior Member
    Join Date
    Apr 2007
    Posts
    17
    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

  7. #7
    Member
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    66
    _parent._parent.money--;

    is the same as

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

    so try

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

  8. #8
    Junior Member
    Join Date
    Apr 2007
    Posts
    17
    It worked fine. Thanks !

  9. #9
    Intermediate Game Dev pseudobot's Avatar
    Join Date
    May 2008
    Location
    New Zealand
    Posts
    561
    ^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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center