A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: math or button problem?

  1. #1
    Senior Member
    Join Date
    Jun 2005
    Posts
    132

    math or button problem?

    ok, this is REALLY stupid problem. onMy Program (go bikes, atv, select an engine type, then options in the bottom right, then weapon systems, and then select one of the fixed weapon mounts) i have a pair of buttons that add or subtract ammo space. These are the functions that the button calls:

    Code:
    function upammo() {
    	if (bin<(firmpoint+hardpoint)) {
    		bin += .2;
    	} else {
    		clearInterval(countID);
    	}
    }
    function downammo(){
    	if(bin>0){
    		bin-=.2
    	}else{
    		clearInterval(countID)
    	}
    }
    And this is what's on the button

    Code:
    on (press) {
    	upammo(); // call the function once - the instant ythe button is pressed
    		countID = setInterval(upammo, 100);
    		makenotes()
    }
    
    on (release, releaseOutside) {
    	clearInterval(countID);
    }
    (with replacements for downammo as approriate)

    Now, the problem is that it doesnt stop at either the high max (the total of firmpoints and hardpoints installed), if theres more than 2 installed (it goes to 2.2, but stops at 1 with only 1 mount) nor at 0 when you're uninstalling the ammo bins(it goes from 0, to 5.551115.... to -.2)

  2. #2
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    bump to see if anyone has any ideas on this yet. I know it's a minor problem, but still, because it's possible to actually stop the funcky numbers, i'd like to have it fixed. Could it be a timing issue with the interval? too fast or too slow? (at 1/10th of a second, i doubt that, for both cases)

    I just added another variable, that counts up to 10 per weapon mount installed ( using (firmpoint+hardpoint)*10) ), and it now counts up and down correctly, except for removing the last .2 installed, which then produces a number of -3.88578...

    i'm confused, and...

    myheadhurtsalot...

  3. #3
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    bump again

  4. #4
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    did you ever define the variable bin?

    Depending on what you publish to, it might be your problem.
    Put
    bin=0;
    before using it..
    My letters on the F1 key have faded, how are yours today?

  5. #5
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    got that, it's stated early on in the program. Otherwise, it would report as NaN, i think.

  6. #6
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Hmm your code looks fine to me..
    Hard to guess, what is going wrong, any chance, you could post the fla?
    My letters on the F1 key have faded, how are yours today?

  7. #7
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    sure it's at www.geocities.com/daherm3610/vehicle.fla

    Unfortunately, because it's geocities, i have a low per hour bandwidth limit, so if you can't get it right away, come back the next hour

  8. #8
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Hmm, i am not totally sure, but it looks like at it is the old calculation
    failure.. ( some rounding problems, when not calculating with ints)

    You could make sure, that the bin value doesn't get above/below what you want it with the following code:
    Code:
    upammo(){
      if (bin<(firmpoint+hardpoint)) {
        bin = Math.min(bin + .2,(firmpoint+hardpoint));
    Code:
    function downammo(){
      if(bin>0){
        bin = Math.max(bin-.2,0);
    My letters on the F1 key have faded, how are yours today?

  9. #9
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    tried that, it didnt help <sigh>

  10. #10
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Hmm.. that is hardly possible. But i believe you.

    Sorry to say, but your code is close to unreadable
    I will have another look tomorrow, for now my clanmates
    wanna play with me..
    My letters on the F1 key have faded, how are yours today?

  11. #11
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    has anyone else taken a look at this lately, I'm republishing the site (same link as above). The code now being used looks like this:
    Code:
    function upammo() {
    	if (bin<(firmpoint+hardpoint)) {
    		bin = Math.min(bin+.2, (firmpoint+hardpoint));
    	} else {
    		clearInterval(countID);
    	}
    }
    function downammo() {
    	if (bin>0) {
    		bin = Math.max(bin-.2, 0);
    	} else {
    		clearInterval(countID);
    	}
    }
    Per Mcusher's suggestion.

    As far as the code is concerned, if you want me to repost the FLA i will try and clean it up and put different stuff in layers to hopefully help some more.

  12. #12
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    bumpage

  13. #13
    Senior Member
    Join Date
    Jun 2005
    Posts
    132
    tag this again. The issue is that when reducing the amount of ammo space, it works, but will also show up a really funky number before it gets to 0, meaning, i'll be at like .2 or .4, and all of a sudden it will jump to something like 2.7486391 or something, and then go to 0.

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