Ron, what is the number of rows that is intended to be passed into your function? I assume that it is the total number of rows in the table. I assume this because I’ve not been able to get it to work correctly any value other than the total number of rows, and I ask because there is definitely a problem with the code: some kind of misaddressing, apparently based on the number of rows in the table, can cause searches to fail. I haven’t been able to identify the precise parameters yet, but since I’m leaving tomorrow morning for a week that will have no Inform in it, I thought I’d post this while what I have discovered is fresh in my skull.
Both your code and mine (which is based on your code, but with the number of rows supplied by the TableRows() function) fail on the code below, but only if you remove the “with 2 blank rows” from the table definition. Even without the 2 blank rows, the linearsearch functions will work on the first two rows of the table, but fail to return the third row. The number of columns in the table doesn’t appear to make any difference (I’ve tested this table with 2 and 3 columns).
[code]
Include (-
Global seekStartAddress;
Global seekRows;
Global seekVal;
Global seekReturnValue;
-) after “Definitions.i6t”.
To select a/the/-- row with (TC - a word value valued table column) of (W - a word value) in/from (T - table name):
(- {-require-ctvs}
ct_0 = {T};
ct_1 = -1;
seekRows = TableRows({T});
!print "rows: ", seekRows, "; value: ", {W}, ". ";
seekStartAddress = ({T})–>(TableFindCol({T}, {TC}, true)) + (COL_HSIZE * WORDSIZE);
seekVal = {W};
@linearsearch seekVal WORDSIZE seekStartAddress WORDSIZE seekRows 0 4 ct_1;
if (ct_1 < 1) return RunTimeProblem(RTP_TABLE_NOCORR, {T});
-).
Include (-
Global quickloopSearchFor;
Global quickloopStartAddress;
Global quickloopRowsLeft;
Global quickloopReturnValue;
-) after “Definitions.i6t”.
To repeat through (tab - table name) until (row - number) with (tc - a word value valued table column) as (val - a word value) begin – end:
(- {-require-ctvs} ! {-zero-counter:reviewHistoryCol}
ct_0 = {tab};
!print "rows: ", {row}, "; value: ", {val}, ". ";
ct_1 = -1;
quickloopSearchFor = {val};
quickloopStartAddress = ({tab})–>(TableFindCol({tab}, {tc}, true)) + (COL_HSIZE * WORDSIZE);
quickloopRowsLeft = {row};
quickloopReturnValue = -1;
while (1) {
@linearsearch quickloopSearchFor WORDSIZE quickloopStartAddress WORDSIZE quickloopRowsLeft 0 4 quickloopReturnValue;
quickloopReturnValue++;
if (quickloopReturnValue == 0) break;
ct_1 = ct_1 + quickloopReturnValue; ! set the chosen row for I7
quickloopStartAddress = quickloopStartAddress + (WORDSIZE * quickloopReturnValue); ! set start point for next iteration
quickloopRowsLeft = quickloopRowsLeft - quickloopReturnValue; ! decrease #/rows left to check
!-).
When play begins:
say “Rows: [number of rows in the Table of Smiles].”;
select row with a smile number of 2 in the Table of Smiles;
say “smile 2 is [key entry] by the lights of the new ‘select…’ phrase.”;
repeat through the Table of Smiles until (the number of rows in the Table of Smiles) with smile number as 2:
say “smile 2 is [key entry] by the lights of the new ‘repeat…’ phrase.”
There is a room.
Table of Smiles
smile number key
0 “: )”
1 “; )”
2 “:->”
with 2 blank rows[***Remove these blank rows to see lookup fail][/code]
My little WIP has another table that seems to work when it is declared empty with 99 blank rows, but not if declared with 100 blank rows; again, much of the table is searched correctly, but data near the bottom (the last two filled rows) is not found.
If I get a chance tonight, I’ll try taking a look at the actually I6 array content and see how it matches up with the seek addresses…
Thanks,
Erik