A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Help Me, Need To Know Cannot ActionScript

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    6

    Help Me, Need To Know Cannot ActionScript

    Hey Guys,
    I'm Making a military based game with a store to buy things. In the game you have $1000 to start and I want to buy a $50 item. I Know how to buy these items but my cash is able to go below 0. How Do I stop This From Happening?
    I Made a Variable Already Called CashBox and I have some code on a frame at the begining of the movie;

    var CashBox:Number = 1000;
    CashBox <> 0;
    var WishToBuy:Number = 0;

    WishToBuy is the amount of money I Wish to spend anyways ya.
    I was told that <> means Cannot so I Put that into the code but Since My Cash Still Goes Below 0. I Think That's False. So I Need To Know The Cannot = sign for ActionScript and Please Fix The Code I have if there's anything wronge with it.

    Also On The Button That's Says Buy on it I Have The Code,

    on (release) {
    _root.CashBox -= 50;
    _root.CashBox <> 0;
    }
    // <> I Think It Means Does Not. Not Cannot. *Just a side Note*

    Anyways Ya, If You Know The Answer, Please E-Mail Me The Answer To This At DanielBiro@Hotmail.com

  2. #2
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    <> does not mean cannot, it is a (deprecated) operator to test if two values do not equal each other...see:

    http://livedocs.adobe.com/flash/8/ma....html#wp182024

    What you need is a conditional check to test if your funds available are greater than the cost of the item - if so, allow the purchase...ie:
    code:

    var cash=1000;
    var price=50;

    function purchase(quantity, price){
    var cost=quantity*price;

    if(cash>=cost){
    cash-=cost;
    trace("purchase approved. Cash remaining: "+cash);
    }
    else{
    trace("purchase failed - not enough cash");
    }
    }

    purchase(1,50); // ok

    purchase(10,500); // fails



    HTH,

    K.

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    6
    Quote Originally Posted by deadbeat
    <> does not mean cannot, it is a (deprecated) operator to test if two values do not equal each other...see:

    http://livedocs.adobe.com/flash/8/ma....html#wp182024

    What you need is a conditional check to test if your funds available are greater than the cost of the item - if so, allow the purchase...ie:
    code:

    var cash=1000;
    var price=50;

    function purchase(quantity, price){
    var cost=quantity*price;

    if(cash>=cost){
    cash-=cost;
    trace("purchase approved. Cash remaining: "+cash);
    }
    else{
    trace("purchase failed - not enough cash");
    }
    }

    purchase(1,50); // ok

    purchase(10,500); // fails



    HTH,

    K.
    what do i put that code on though?
    does it matter?

  4. #4
    Junior Member
    Join Date
    Mar 2007
    Posts
    6
    Quote Originally Posted by Dbiro
    what do i put that code on though?
    does it matter?
    oh, and on that code I replace price with _root.WishToBuy and Cash With _root.CashBox?

    also, the button that you press only lets you buy 1 of the item at a time. so would i replace quantity with 1?

  5. #5
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    Yeah, if you can only ever buy 1 item at a time, you can do away with the quantity part altogether...

    The key part of that code is the if statement which checks whether there are enough funds available to purchase the item, and then accepts or rejects the purchase accordingly...

    K.

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