5 Replies Latest reply on May 13, 2009 11:11 AM by wwscoper

    update "money" variable with a function

    wwscoper

      Hi all,

       

      I am creating a roullete wheel type game. I am having a problem updating a total when I call a function to add the variables. I have a variable "myMoney" that is initialized at 50. After I spin the wheel, I want to add the bets to the current value of "myMoney." I have another variable, "slot1Bet" that is initialized at 0. I am trying to call the function updateMoney(myMoney) which than should take the current value of "myMoney" and set it equal to itself plus the slot1Bet. The trace statement for "money equals...." returns 500 and so does the updateMoney function. I would appreciate any help solving this problem so the correct value is returned based on the slot bet.

       

       

      _global.myMoney = 50;

      _global.slot1Bet = 0;

       

      trace("updated money equals " + updateMoney(myMoney));

       

       

      var updateMoney = function(money:Number){

      money = money + slot1Bet;

      trace("money equals" + money);

      trace("myMoney equals" + myMoney)

      trace("slot 1 bet equals" + slot1Bet);

      return money;

      }

       

       

      ***********************************************

       

      I think one problem is that I had some code on a draggable movieclip with a button inside. I've changed that to just be a draggable mc. I also updated the function to:

       

      //Calculate the users new money after the wheel has been spun.

      var updateMoney = function(money:Number){

      trace("money equals" + money);

      trace("myMoney equals" + myMoney)

      trace("slot 1 bet equals" + slot1Bet);

      return money * money;

      }

       

      This function returns the correct value of 2500 but if I change the last line from, "return money*money" to "return money + slot1Bet;" I get 5025. Why is the bet being added to the end of the number and not actually adding to the total.