ColorizeScript challenge

Ray Horsley ray at linkitonline.com
Tue Apr 25 18:27:33 CDT 2006


Hi Richard,

I've found the 'repeat for each' structure, the first one below, to be 
incredibly faster than the second and third ones below since it doesn't 
have to count returns or spaces to get to lines and words.  For 
example, in the second repeat loop I believe the second line 'put line 
cline of s into curline' is going to take a long time to count all 
those return characters in long scripts, so I believe replacing the 
'repeat while...' structure with another 'repeat for each line' 
structure would speed things up substantially.  In the third repeat 
loop there's a similar situation with the 'repeat with curword...' 
structure.  Here a 'repeat for each word...' structure might speed 
things up substantially, also.  Of course, in each of these 
replacements you'll have to add 1 to a variable for each repetition in 
the loop so you know where you are, but that's just math which isn't 
going to slow anything down.

Hope this helps,

Ray Horsley
Developer, LinkIt! Software


On Apr 25, 2006, at 7:00 PM, Richard Gaskin wrote:

> Anyone have ideas on how to speed up MC's script colorizing?
>
> Here's the handler from the card script of the Script Editor stack:
>
>
> on colorizescript
>   if tokencolors["if"] is empty then setupcolors
>   local s
>   put field "Editor Field" into s
>   put s into field "Editor Field"
>   go to card 2
>   local curword
>   put 1 into curword
>   repeat for each word w in s
>     if tokencolors[w] is not empty
>     then set the textColor of word curword of field "Editor Field" of 
> card 1 to tokencolors[w]
>     add 1 to curword
>   end repeat
>   local oldline, cline, curline, nwords
>   put min(lineoffset("#", s), lineoffset("--", s)) into oldline
>   put 0 into cline
>   repeat while oldline is not 0
>     add oldline to cline
>     put line cline of s into curline
>     put the number of words in curline into nwords
>     repeat with curword = 1 to nwords
>       if char 1 of word curword of curline is "#" or char 1 to 2 of 
> word curword of curline is "--" then
>         set the textColor of word curword to nwords of line cline of 
> field "Editor Field" of card 1 to "DarkOrchid4"
>         exit repeat
>       end if
>     end repeat
>     put min(lineoffset("#", s, cline), lineoffset("--", s, cline)) 
> into oldline
>   end repeat
>   go to card 1
>   unlock screen
> end colorizescript
>
>
> On short scripts it's fine, but run it on lengthy ones like libURL and 
> it takes some time.
>
> Any suggestions welcome...
>
> -- 
>  Richard Gaskin
>  Fourth World Media Corporation
>  ___________________________________________________________
>  Ambassador at FourthWorld.com       http://www.FourthWorld.com
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
>



More information about the metacard mailing list