7 Replies Latest reply on Aug 6, 2009 5:05 PM by Roulette System Player

    updating bets based on _droptarget

    wwscoper

      I have another question on my roulette game that I am building.

       

      The bets for the game are being placed by dragging a chip to a slot on the table. There are six slots, with numbers 1-6, 6-12, 12-18, etc....

       

      I have a $25 chip and a $5 chip. I am using _droptarget to detect when a chip has been placed on one of the slots. If a $25 chip is placed on "slot1",

      slot1Bet += 25;

       

      Now the tricky part...if I move the chip from slot1 to another slot before the roulette wheel is spun, I need to change the bets so that "slot1 -=  25" and another slot gets the bet added. I'm calulating the final results by using something like this:

       

       

      if (winningNumber<= 6){

      return Number(money) + Number(slot1Bet) - Number(slot2Bet) - Number(slot3Bet) - Number(slot4Bet) - Number(slot5Bet) - Number(slot6Bet);

       

       

      Any ideas?

       

      Thanks!

       

      P.S. sorry for reposting this, but I thought it better to start a new thread since my last question was answered.

        • 1. Re: updating bets based on _droptarget
          kglad Adobe Community Professional & MVP

          you could define a property of each chip that stores its slot.  when a chip is dropped check its property to see if you need to update a slotbet (ie, the property is defined) and then update its property.

          • 2. Re: updating bets based on _droptarget
            wwscoper Level 1

            Thanks Kglad! I hope your in for another question.

             

            I have set a property for my chips like this: twentyfiveChip_mc.slot = undefined;

             

             

            I have code like this when the chips are dropped on a slot:

             

            if(twentyfiveChip_mc._droptarget == "/slot1"){

            twentyfiveChip_mc.stopDrag();

            if (twentyfiveChip_mc.slot == undefined){

            slot1Bet += 25;

            } else updateSlotBet();

            twentyfiveChip_mc.slot = 1;

            trace("You have a 25 chip on slot " +twentyfiveChip_mc.slot);

            trace("Slot 1 bet is " + slot1Bet);

               } else if (twentyfiveChip_mc._droptarget == "/slot2"){

               twentyfiveChip_mc.stopDrag();

               if (twentyfiveChip_mc.slot == undefined){

               slot2Bet += 25;

               } else updateSlotBet();

            twentyfiveChip_mc.slot = 2;

               trace("You have a 25 chip on slot " +twentyfiveChip_mc.slot);

               trace("Slot two bet is " +slot2Bet);

             

            I'm trying to figure out what the updateSlotBet function will look like. I'm going to sleep on this one, but if you have an idea...I'd love to hear it!

             

            Thanks!

             

             

             

             

             

             

             

            • 3. Re: updating bets based on _droptarget
              kglad Adobe Community Professional & MVP

              i would approach this with some fore-planning.  first, i would have each chip have a value property (how much it's worth), in addition to a slot property to indicate which slot the chip is placed on.  (btw, you do not need to intialize chip.slot=undefined.  chip.slot will be undefined unless you explicitly define it which you're not going to do unless it's dropped on a slot).

               

              and each slot1,..,slot36,slot0,slot00 i would add to a parent movieclip (say table) and assign it a property storing its slot number (though this can be derived easily using the slot movieclip's _name property and the flash string methods).

               

              and i would create the initial setup using some parameters to give you more flexibility:

               

              var chipValA:Array=[1,5,25,100];  // chip values

              var chipNumA:Array=[20,20,20,20];  // number of $1, $5, $25, $100 chips.

               

              i would create 1 of each of those chips and assign a linkage id:  chip1_ID,chip5_ID,chip25_ID,chip100_ID

               

              you could then code:

               

              var dep:Number = 0;

              for(var i:Number=0;i<chipNumA.length;i++){

              for(var j:Number=0;j<chipNumA[i];j++){

              var mc:MovieClip = this.attachMovie("chip"+chipValA[i]+"_ID","chip_"+dep,dep++);

              mc.value=chipValA[i];

              // assign _x and _y properties

              mc.startX=mc._x;

              mc.startY=mc._y;

              mc.onPress=function(){

              this.startDrag();

              }

              mc.onRelease=mc.onReleaseOutside=function(){

              for(mc in table){  // loops through all the slots

              if(typeof(table[mc])=="movieclip"&&table[mc]._parent==table){

              if(eval(this._droptarget)== table[mc]){

              if(table[mc].chip==undefined){

              this._x=table[mc]._x;

              this._y=table[mc]._y;

              this.slot=table[mc].slot;

              table[mc].chip=this;

              } else {

              // this slot already has a chip on it.  decide what to do.  replace previously placed chip, add to slot or return this chip to its startX,startY

              }

              } else {

              this._x=this.startX;

              this._y=this.startY;

              }

              }

              }

              }

               

              then when your wheel spins you can loop through all the table children like above (to loop through all the slots), to see which have a chip property.  the chip property references the chip(s) placed on that slot and has(have) a value property so you can determine the amount won.

               

              after each slot's payout is determined, reassign the slot's chip property to undefined.

               

              if a slot can hold multiple chips, make its slot property an array so you can push chips into the array should there be more than one chip placed on a slot.

              • 4. Re: updating bets based on _droptarget
                wwscoper Level 1

                Thanks Kglad!

                 

                I ended up solving the problem sticking with value and slot properties like you suggested before. Thanks for this other script though. If i have to do something like this again I have a better idea what is involved.

                • 5. Re: updating bets based on _droptarget
                  kglad Adobe Community Professional & MVP

                  you're welcome.

                  • 6. Re: updating bets based on _droptarget
                    wwscoper Level 1

                    I don't mean to advertise here, but thought the forum members might like to see the final project that was possible from the great help received here. Thanks everyone!

                     

                    http://www.pediatricaidshivcare.org/casinonight/