A Flash Developer Resource Site

Results 1 to 20 of 22

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

Threaded View

  1. #21
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Ralgoth your cycle2 has a logical problem...
    Code:
    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:
    Code:
    //edit:
    //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.

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