Speed up a slow loop

Ken Ray kray at sonsothunder.com
Thu Mar 3 16:42:51 EST 2022


How about using the 'difference' command? Here's a simple example:

on mouseUp
   put "true" into tDict["test"]
   put "true" into tDict["word"]
   put "true" into tDict["ball"]
   put "test" & cr & "ball" & cr & "boat" & cr & "unicorn" into tUserWords

   split tUserWords by cr and tab
   difference tUserWords with tDict
   if tUserWords is not an array then
      answer "All words matched!"
      answer "Sorry, try again, these words didn't match:" & cr & cr & (the keys of tUserWords)
   end if
end mouseUp

If you run this, it will say that "boat" and "unicorn" don't match; if tUserWords is "test" and "ball" you get "all words matched".

Will this work?


> On Mar 3, 2022, at 2:34 PM, J. Landman Gay via use-livecode <use-livecode at lists.runrev.com> wrote:
> On 3/3/22 2:00 PM, Tom Glod via use-livecode wrote:
>> But what prevents you from loading all your data into an array?  and just
>> iterating over the keys or index of an array?  vs the lines of a long list.?
>> That will yield the fastest performance.
> Right, it's an array, and I don't iterate. I just check the array key directly for a value.
> I realize I'm kind of monopolizing things here. I wrote the game for myself and I ignored the speed issues and just played it on my tablet where it works fine, but now someone else wants to include it in a distributed app so I need to figure it out.
> -- 
> Jacqueline Landman Gay         |     jacque at hyperactivesw.com
> HyperActive Software           |     http://www.hyperactivesw.com
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Website: https://www.sonsothunder.com

More information about the use-livecode mailing list