'Array' of hope for Array lookups...
Author:  DeadmanDines

Submitted:  30th May, 2003

Views:  2466
 Rated: 


Ever tried reading from an entire array in one big loop? Tried using aaaaall those counters and events to check if you've reached the end of the first dimension, then moving onto the right position in the second and third ones, and blah blah blah, pointless... waste... of... time...
...and by the time you've finally got your array system working, you've forgotten what you were doing it for in the first place!
Well, imagine if you could just get it to find which array item you were at just by using the loop index number? Imagine if there was a way of getting MMF to realise that, if it's at loop 34, for example, then it would be at, say, item 4,6,1.
Well, after much toil (considering how bad I am at maths), I found a way to do it. You mathematicians out there could probably simplify it down a lot, so feel free to add any comments which could help.
So, how do we do it? For this, you will need:
1. A pack of pringles (crucial)
2. Binary object
3. Base Converter object
4. MMF1.5
Then, you use the following expressions. [value] means the loop number (eg: loop number 30), [size of x] means the maximum size of the x dimension, and so on.
x dimension = [value] mod [size of x]
y dimension = (([value]([value] mod [size of x]))/[size of x]) mod [size of y]
z dimension = (((([value]([value] mod [size of x]))/[size of x]) mod [size of y]) mod [size of y]) mod [size of z]
I don't even want to begin explaining how they work (mainly because I created them a lot through trial and error, so I can't remember most of it!!), so I won't, heh. To avoid getting any of the expressions wrong, I recommend pasting them into the expression editor, and replacing the bits in brackets with their various equivalents (eg: replace '[value]' with 'loopindex (loopname)').
However, we have a small problem. If, like me, you're doing this to work with array files which were NOT generated by your application (in other words, ones which could be of any size, in any dimensions), then you have no way of finding out the [size of x/y/z] variables...
...or do you?
Yes, you do. They're not exactly the clearest marked expressions in MMF, but you click the X Dimension/Y Dimension/Z Dimension expressions in the array object, and that should get how big the current array file's dimensions are. Failing that, you could always use the binary object to read a long integer at bytes 14d, 18d and 22d for the x y and z dimensions respectively (the d means that those numbers are in decimal, not hex ). You choose which one suits your application better.
If the array is 1based, you'll also need to add 1 to each of the dimensions you retrieve from the above expressions.
That's where we encounter a much graver problem. The array object doesn't tell you if the loaded array is base 0 or base 1! So, we need to use the Binary object, and the Base Converter object.
Get the binary object to load the array, and retrieve a single byte at 26d. THEN, convert that value via the Base Converter into binary. You should get a string with 32 characters.
We're only interested in the 3rd character from the right. If it's a 1, then your array file is base 1. If it's a 0, then the array is base 0.
Just PM me, or add a comment to this post, if you want more information about how to do this stuff with the binary object. Feel free to also ask about any of the other stuff in this article.
Once you've got it working, bask in the glory, eating your pringles.


DeadmanDinesBest Article Writer Registered 27/04/2006
Points 4758
