# Confused with this seemingly simple problem

• Barikoopa
• Newbie
• Joined: Apr 26, 2006
• Posts: 7
• Status: Offline

December 19th, 2007, 7:34 pm

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
• Anonymous
• Bot
• Joined: 25 Feb 2008
• Posts: ?
• Loc: Ozzuland
• Status: Online

December 19th, 2007, 7:34 pm

• digitalMedia
• a.k.a. dM
• Joined: Dec 29, 2003
• Posts: 5169
• Loc: SC-USA
• Status: Offline

December 20th, 2007, 7:09 am

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.
- dM
• BrianTheMapper
• Newbie
• Joined: Jan 09, 2008
• Posts: 13
• Loc: Indiana
• Status: Offline

January 10th, 2008, 8:33 pm

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 38 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

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.