A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 22 of 22

Thread: Logic Bomb... Retrieving "negative" index, and wrap around an Array?

  1. #21
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Alhama de Granada, España
    Ralgoth your cycle2 has a logical problem...
    function cycle2(len:uint,position:int):uint
        if(position < 0) position = len + -position;
        return position%len;
    len = 10
    position = -1
    position = len + -position == 11
    11%10 = 1
    but position -1 should correspond to item [9] in the array.

    What about:
    //edit #3. argh:
    position = position<0 ? len-(-position%len) : position%len;
    ///edit: alright I think I finally got it, I'm too wasted to be doing this at 12:30 am...

    ///edit #47, I think I just reproduced what Moagrius did like six posts ago by trial and error. Just shoot me please.
    Last edited by joshstrike; 01-19-2010 at 04:29 AM.

  2. #22
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    haha, yeah I didn't get it right until I woke up at 6AM after the whiskey wore off. (most of my friends drunk dial/text... I give drunk coding advice)

    it ended up that you cant check if position is a negative, you have to do the modulo first. otherwise if the position is a multiple of the len then the modulo would be 0, and no longer a negative.

    the above code would return the array's length (len-(0)).

    --- edit --- whiskey goes well w/ coffee.
    Last edited by Ralgoth; 01-19-2010 at 10:33 AM.
    Search first, asked questions later.

Tags for this Thread

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