Results 1 to 13 of 13
  1. #1
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default I need some ideas on this: Browsing through an array.

    So I believe this is quite easily done and obvious, I just can see how it works at the moment.

    I have an array. And I want to get info from item 1 in that array, then when a function is run, switch to item 2, next time, item 3, and so forth. Preferably jumping back to 1 when the end is reached if that is possible.
    I have seen the segment on iterating through dynamic arrays on the UDN, but I can't quite see how it works or if I even can use it for this.

    What would I need for something like this?

    I just need to know how to get info from a specific index in the array basically, and how to continously iterate to the next, rather than hardcoding it all, the rest I can handle myself, I believe.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  2. #2
    Iron Guard
    Join Date
    Nov 2007
    Location
    USA
    Posts
    692

    Default

    This is very basic control structure. I'm thinking it would be a disservice to you to just give you a code snippet.

    You need a class variable as a counter, on each function call test to see if it is less than the length of the Array, if it is then increment it otherwise set it to zero and then access the Array with the counter as the index.

  3. #3
    MSgt. Shooter Person
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    144

    Default

    A handy way to wrap a number back to 0 is to use a mod function - ie, x=(x+1) % limit will cycle through values 0, 1, ... , limit-1

  4. #4
    MSgt. Shooter Person
    Join Date
    Jul 2011
    Posts
    484

    Default

    var array<int> arr;
    var int cur;
    function int get()
    {
    cur=(cur+1)%arr.length;
    return arr[cur];
    }
    defaultproperties
    {
    cur=0
    }

  5. #5
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    I see, so that gives me a number based on the length of the array. I think I can use this.
    However, I am actually uncertain of how to access the content of an array, say the count is 3, how do I access the 3rd item in the array?
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  6. #6
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    3rd_item_in_the_array = the_array[2];

  7. #7
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Ah that's right! Now I remember!

    Thanks!
    Last edited by Graylord; 04-17-2012 at 04:30 PM.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  8. #8
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Brisbane Australia
    Posts
    283

    Default

    Strange, I would put a log next to the DrawUIText call, just to make sure SelectedItem is still initialized. Is Selected Item a global variable? Is it being destroyed when the array iteration function's scope is left? If they are in the same function, then there MUST be something changing the value of SelectedItem between when you set it and use it.

    -Mega


  9. #9
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Sorry, I was deleting the post because it was due to a muckup on my part, I was setting the default value in a function I did not know was updating each tick.
    Last edited by Graylord; 04-17-2012 at 07:46 PM.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  10. #10
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Though I do have an issue. How can I do this backwards? Doing cur=(cur+1)%arr.length; works fine as long as I stay on the positive side of the int, but if make a back button but doing -1 instaed of +, once it reaches 0, it will keep going into -1 giving me an out of bounds error and trying to go back to 0 gives me an "zero modulo" (?) error.
    Last edited by Graylord; 04-17-2012 at 11:43 PM.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.

  11. #11
    MSgt. Shooter Person
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    144

    Default

    There seems to be something wrong with this thread... I could have sworn it wasn't Graylord that started it and every time I try to go to the second page it sends me back to the first... maybe its just my browser?

    Anyway, to go backwards you can take advantage of the modulo function - use:

    cur=(cur-1+arr.length)%arr.length

  12. #12
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Quebec, Canada & Florida, USA
    Posts
    279

    Default

    Use a for or while loop, and increment an int by 1 everytime... use that int as the number for your array slot

  13. #13
    Marrow Fiend
    Join Date
    Jun 2009
    Posts
    4,501

    Default

    Quote Originally Posted by paco View Post
    There seems to be something wrong with this thread... I could have sworn it wasn't Graylord that started it and every time I try to go to the second page it sends me back to the first... maybe its just my browser?

    Anyway, to go backwards you can take advantage of the modulo function - use:

    cur=(cur-1+arr.length)%arr.length
    Cheers, that's working perfectly!

    As for the issues, I'm definitely the OP, and it was taking you back to the first page as before your post there was no second page. You you got a tab to access the second page, I have no idea though.
    Please don't send me private messages asking how to use UDK unless it has to do with my work, everything I can teach is already out there.

    I am not support, I am here to learn myself.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.