We will also need a routine to deal with the recipes - which comes later. For now we will just add a comment and the outline of a loop.
Here is the location - between the end of the conversion loop and the start of the group loop.
...(conversion loop)... if thisValue < 0 MainObject[ i ].isGroup = 1 else MainObject[ i ].isGroup = 0 endif endif next i // Recipes Go Here for i=topObject() + 1 to thisArraySize next i // Clear Temp Array dim tempArray[ 0 ] // Group Memberships for i=1 to topObject() if ObjectIsGroup( i ) > 0 and ObjectDetail( i ) <> "" ...(group membership loop)...Also in this section is where the temp array is cleared.
Within the if/endif block for the object groups - immediately after thisStart is set to one, a new local variables is created to hold the encoded string.
thisCoded$ = ""Now where we had the comment line.
// convert to base96The following lines are used to replace it.
thisObject = FindObjectByName( thisObject$ ) if thisObject > 0 then thisCoded$ = thisCoded$ + Base96Encode( thisObject )This looks for the object name in the object array, and if it is found, encodes it's index using Base96 and adds it to the thisCoded$.
When all the objects have been processed ( after the endwhile command), the string is sorted and put back into the detail$ field.
MainObject[ i ].detail$ = Base96Sort( thisCoded$ )Which completes the group membership encoding.
To test this, we change the group print command to a printc command in the test code.
printc( ", Group: ")And follow it with the following lines.
thisString$ = ObjectDetail( i ) thisNum = len( thisString$ ) / 2 for j = 1 to thisNum thisCode$ = mid( thisString$ , j*2 - 1 , 2) thisObject = Base96Decode( thisCode$ ) printc( ObjectName( thisObject ) ) if j < thisNum then printc( ", " ) next j print( "." )Firstly this transfers the coded string into local variable thisString$, and puts half it's length (the number of encoded objects) into thisNum.
It then performs a loop decoding each one in turn and printing the results. If the one being printed is not the last one, it also prints a comma.
At the end, it prints a full stop and ends the line.
For anyone wondering why tree comes before stone in the member list for resource - which was supposedly sorted when it was encoded.
The answer is, that it was sorted based on the object index, not it's name. In index order, they are sorted.
If we want them sorted by name, then we have two choices.
- Sort the object array by object name when first read
- Add another function to sort the group members based on object name.
No comments:
Post a Comment