# Simple counting logic problem

**URL:** <https://forum.kirupa.com/t/simple-counting-logic-problem/215855>\
**Category:** Uncategorized\
**Created:** [February 11, 2007, 11:11am UTC](https://forum.kirupa.com/t/simple-counting-logic-problem/215855 "2007-02-11T11:11:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scriptrookie](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@scriptrookie](https://forum.kirupa.com/u/scriptrookie)\
**Post date:** [February 11, 2007, 11:11am UTC](https://forum.kirupa.com/t/simple-counting-logic-problem/215855/1 "2007-02-11T11:11:30Z")

</div>

hi guys,

id like to ask for help with my counting logic script. what i want to do is display a set of items by 10, so clicking next\_btn shows the next 10 items and also adds 10 items to the start\_count var so that the next set starts at the first count (ie 21,31, 41…). counting seems to work fine even if the limit\_count var is 54, which shows only 51,52,53,54.

The problem is the backward counting, the operation looks normal but the logic is wrong, when i click the prev\_btn the set is repeated (ex. click next appears 1-10, click next again shows 21-30, click prev shows 21-30).

I’ve attached the code below so that you can see what i mean. I think my logic seems wrong somewhere along the code. I tried to play around with the variables but it gets more confusing. Has anyone experienced a similar thing like this before? Any advice you can share would gladly be appreciated.

Thanks a million!  
\_ScriptRookie

```auto

var limit_count = 54;
var start_count = 1;
var end_count = 0;
prev_btn.enabled = false;
prev_btn._alpha = 40;
function nxt(nxtNum) {
 prev_btn.enabled = true;
 prev_btn._alpha = 100;
 end_count += nxtNum;
 if (end_count>=limit_count) {
  end_count = limit_count;
  next_btn.enabled = false;
  next_btn._alpha = 40;
 }
 for (i=start_count; i<=end_count; i++) {
  trace(i);
 }
 start_count += nxtNum;
 if (end_count>=limit_count) {
  start_count -= nxtNum;
 }
 trace("start: "+start_count);
 trace("end: "+end_count);
}
function prv(prvNum) {
 start_count -= prvNum;
 if (start_count<=1) {
  prev_btn.enabled = false;
  prev_btn._alpha = 40;
 }
 for (j=start_count; j<=end_count; j++) {
  trace(j);
 }
 end_count -= prvNum;
 trace("start: "+start_count);
 trace("end: "+end_count);
}
next_btn.onRelease = function() {
 nxt(10);
};
prev_btn.onRelease = function() {
 prv(10);
};

```
