Speed up a slow loop
kray at sonsothunder.com
Thu Mar 3 16:42:51 EST 2022
How about using the 'difference' command? Here's a simple example:
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)
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:
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
More information about the use-livecode