In need of speed; Array errors

Terry Vogelaar terry at discovery.nl
Fri May 17 09:21:01 EDT 2002


I need to do calculations with sets of 3 cards in a stack. It seems wise to
me to copy the data into an array first and then repeat through the array
instead of through the stack. But it still is a terribly slow script. Are
there any suggestions to help me make this work faster? The slow but
correctly working version is this:

on mouseup
  repeat with e = 1 to the number of cds
    put the short id of cd e into ky
    put fld "data" of cd e into advs[ky]
  end repeat
  put the keys of advs into vKeys
  repeat with e = 1 to the number of lines of vKeys -2
    put advs[line e of vKeys] into eVar
    repeat with f = e+1 to the number of lines of vKeys -1
      put advs[line f of vKeys] into fVar
      repeat with g = f+1 to the number of lines of vKeys
        put advs[line g of vKeys] into gVar
        -- some more lines of script, unimportant for this post
      end repeat
    end repeat
  end repeat
end mouseup

The script basically needs to compare data of 3 different cards. So if the
number of cards is 10, the sequence would be:
1-2-3
1-2-4
1-2-5
...
1-2-10
1-3-4
1-3-5
...
1-9-10
2-3-4
...
8-9-10

The execution takes already 15 minutes and there is more code to add. So I
wondered if I could speed it up using "repeat for each" wherever possible.
This demands some extra code. I also might need 3 copies of the 'advs'
array:

on mouseup
  repeat with e = 1 to the number of cds
    put the short id of cd e into ky
    put fld "data" of cd e into advs[ky]
    put advs[ky] into advsA[ky]
    put advs[ky] into advsB[ky]
    put advs[ky] into advsC[ky]
  end repeat
  put the keys of advs into vKeys
  put 0 into e
  put 0 into f
  put 0 into g
  delete variable advsC[line 1 of vKeys]
  delete variable advsA[line -2 of vKeys]
  delete variable advsA[line -1 of vKeys]
  delete variable advsB[line -1 of vKeys]
  repeat for each element eVar in advsA
    add 1 to e
    delete variable advsB[line e of vKeys]
    repeat for each element fVar in advsB
      add 1 to f
      delete variable advsC[line f of vKeys]
      repeat for each element gVar in advsC
        add 1 to g
        -- some more lines of script, unimportant for this post
      end repeat
    end repeat
  end repeat
end mouseup

Sounds fine to me. But it doesn't work. Right form the start, 'eVar', 'fVar'
and 'gVar' are exactly equal (= the value of the first element in 'advs').
Why? Are those elements not properly deleted in 'advsB' and 'advsC'?

Terry




More information about the use-livecode mailing list