x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Is there an easy way to have an array index loop back to zero when it's larger than the array's length?

Very often I find myself using this pattern: Every time an event fires, I increment an integer: alt text

Then I use that integer to access some element of an array: alt text

That's great, until my integer gets larger than the length of my array. I have to do this whole rigamarole to get it back to zero when necessary: alt text

Is there an easier way to loop an integer back to zero once it gets larger than some number (for instance, the length of an array). I haven't been able to find anything in the docs. Basically it's just a macro for the third screenshot above.

Product Version: Not Selected
Tags:
overflow.jpg (66.8 kB)
overflowresult.jpg (77.8 kB)
resetoverflow.jpg (118.4 kB)
more ▼

asked Oct 22 '17 at 04:35 AM in Blueprint Scripting

avatar image

Ecnassianer
151 4 10 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Modulo! I haven't used it in blueprints, but I'm sure there's a node for it. It's an operator that returns the remainder, in code it's normally represented by %.

So if you do "Index % 3", then it'll just return 3 because we haven't hit the number yet. But when when Index = 5, it'll loop back to 0. Index = 6 returns 1, 7 returns 2, etc. Easiest way to get used to it is just to play around with a calculator that can perform it.

more ▼

answered Oct 22 '17 at 06:23 AM

avatar image

Archduke_
159 2 4 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question