How to edit a script with a script?

Huisingh, Larry R Larry_R_Huisingh at RL.gov
Mon Jan 9 12:13:35 CST 2006


> 
> Hi!
> 
> I have a stack "Karten" with a lot of cards and a lot of images  
> (BiFra1, BiFra2, BiFra3, ... ,BiFra20).
> I want to move the images with the mouse. Therefore I will add the  
> following lines to the scripts of the images:
> 
> on mousedown
>    if the visible of btn "Krtgeaendert" then  # Krtgeaendert means  
> "card is changed". This button is visible when the user is changing  
> the cards
>      grab  
> me                                                            
>       #  
> and it stopps the changing. Only in changing-mode it shall be  
> possible to drag the image to another position.
>    end if
> end mousedown
> 
> Because I don't want to change each script manually I created a  
> little stack and a button with this script:
> 
> on mouseUp
>    global ScriptMerk
>    go stack "Karten"
>    repeat with i = 1 to 20
>      if there is a img ("BiFra" & i) then
>        put the script of img ("BiFra" & i) into ScriptMerk
>        if "on mousedown" is not among the lines of ScriptMerk then
>          add CR & "on mousedown" & CR & "if the visible of btn  
> "Krtgeaendert" then" & CR &\
>             "grab me" & CR & "end if" & CR & "end mousedown" to  
> ScriptMerk
>        set the script of img ("BiFra" & 1) to ScriptMerk
>        edit the script of img ("BiFra" & i)
>       end if
>     end if
>    end repeat
> 
> 
> But when I try to apply the script I get the Script Error:
> 
> if: not a command
> if: error in command
> 
> Metacard is grumbling about the word Krtgeaendert.
> It understand it as a command, because it follows a behind 
> the second  
> quotation mark.
> In what way can I put the name of a button in a script?
> 
> Thanks
> Reinhold

The problem stems from your use of quotes.  You used 
    add CR & "on mousedown" & CR & "if the visible of btn "Krtgeaendert"
then" & CR &\
             "grab me" & CR & "end if" & CR & "end mousedown" to
ScriptMerk

If you go and match the quotes up in pairs from left to right (as
MetaCard does) you will see that the first pair occurs around 
    on mousedown
The next pair occurs around
    if the visible of btn 
After this quote pair MetaCard is expecting a command of some sort since
it is finished with the last quoted string.  The next thing it sees is
    Krtgeaendert
That is why the problem comes up.

One solution is to use special methods to embed quotes in your string.
Use something like this
    add CR & "on mousedown" & CR & "if the visible of btn " & quote &\ 
        "Krtgeaendert" & quote & " then" & CR & "grab me" & CR & "end
if" &\
        CR & "end mousedown" to ScriptMerk

Note the use of the constant named "quote".  It is the equivalent to
NumToChar(34).  There may be other methods but this one should work.
Also, make sure there is a space before the "then" part of the string
you build.  If you don't then MC will think you have a button named
"Krtgeaendertthen" and the if statement will fail when you try to run
this created script.

Larry Huisingh


More information about the metacard mailing list