array help for a disarrayed mind
I'm having trouble with this problem
I have an array like so
#(20, 21, 22, 23, 27, 28, 29, 30)
I need to find min and max values of consecutive elements
so my function would give me (20,23) and (27,30)
Here's what I have so far but i'm not doing it right.
for i = 1 to coneLocTimes.count do (
--coneLocTimes #(20, 21, 22, 23, 27, 28, 29, 30) --example array no need to sort as its already sorted
if conelocTimes[i] == (conelocTimes[i+1] - 1) then --test the first element in the array and see if the next element is consecutive
(
valpt1 = conelocTimes[i]
print i
-- keep looping throught the values until we find one that is none consecutive
for i = 1 to coneLocTimes.count do ( -- start of second loop
if conelocTimes[i] != conelocTimes[i+1] then
(
valpt2 = conelocTimes[i]
)
) -- end of second loop
)
)
Comments
thanks Anubis
The FilterString function is perplexing to me...
I looked it up and I just don't see how it evaluates to
#("20", "23", "27", "30")
intArr = #(20, 21, 22, 23, 27, 28, 29, 30)
#(20, 21, 22, 23, 27, 28, 29, 30)
splitArr = FilterString ((intArr as BitArray) as String) "#{, .}"
#("20", "23", "27", "30")
Is there somewhere else in the maxscript reference I should be looking?
array of strings filterString string token_string [splitEmptyTokens:]
nested action
Yeah, that line:
splitArr = FilterString ((intArr as BitArray) as String) "#{, .}"
actually do a few thinks at once, and they're nested in one line with brackets. If I unfold it, i.e. write the same on steps, it may like --
bArr = intArr as BitArray sArr = bArr as String splitArr = FilterString sArr "#{, .}"
If you execute this line by line you'll see the 'magic' ;)
my recent MAXScripts RSS (archive here)
Anubis thanks. BitArray
Anubis thanks.
BitArray function.... Wow
I like your description
I like your description ("disarrayed mind") ;)
Here is something working:
my recent MAXScripts RSS (archive here)