Confused with this seemingly simple problem

  • Barikoopa
  • Newbie
  • Newbie
  • Barikoopa
  • Posts: 7

Post 3+ Months Ago

I'm making a scrolling game and improvising my own codes based on some ideas I've learned some time ago. What I'm trying to do is make count keep increasing by ones until it is equal to 27, then when it is equal to 27 start to decrease by ones until it reaches 0 again. I want this to continue in a never-ending cycle. At first I tried:
Code: [ Select ]
    if (count = 0) {
        count += 1;
    } else
    if (count = 27) {
        count -= 1;
    }
  1.     if (count = 0) {
  2.         count += 1;
  3.     } else
  4.     if (count = 27) {
  5.         count -= 1;
  6.     }


When that didn't work, I tried:
Code: [ Select ]
   count += num;
    if (count = 0) {
        num = 1;
    } else
    if (count = 27) {
        num = -1;
    }
  1.    count += num;
  2.     if (count = 0) {
  3.         num = 1;
  4.     } else
  5.     if (count = 27) {
  6.         num = -1;
  7.     }


Neither of these worked, I traced count and it stayed at 27 - I'm thinking it's because the first count+=1 was not cancelled before the count-=1 was applied (for the first try at the code). I honestly have no clue about the second try at the code, and no idea on how to fix this problem (and trust me I've tried).

So, does anyone know a system that can make count bounce between 0 and 27 without getting stuck, or even a way to cancel the count+=1 when count-=1 is introduced? I'm still on my way to becoming fluent in actionscript, so any help would be very much appreciated. Thanks in advance to anyone willing to help :)
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

Your if statement should be "if(count==X){}", I believe.

By this logic your count would have to equal 0 or 27 for any action to be taken.
  • BrianTheMapper
  • Newbie
  • Newbie
  • BrianTheMapper
  • Posts: 13
  • Loc: Indiana

Post 3+ Months Ago

Barikoopa wrote:
Code: [ Select ]
    if (count == 0) {
        count += 1;
    } else
    if (count == 27) {
        count -= 1;
    }
  1.     if (count == 0) {
  2.         count += 1;
  3.     } else
  4.     if (count == 27) {
  5.         count -= 1;
  6.     }




I think you could get away with using a loop.

Code: [ Select ]
while(count <= 27) {
    count + 1;
}
while(count >= 0) {
    count - 1;
}
  1. while(count <= 27) {
  2.     count + 1;
  3. }
  4. while(count >= 0) {
  5.     count - 1;
  6. }

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.