Changing a stack script on the fly and other stuff

Jason Vickers jvickers2002 at hotmail.com
Sun Aug 21 10:09:39 EDT 2005


This may seem a little complicated.  At least, it does to me  :-P.  Hopefully my description is understandable.

I have a stand alone app that clones a stack so users can change and save information for later retrieval.  Much of the scripting is put on the stack level.  When the stack is cloned, the scripting is cloned.  One of the stack scripts is as follows:

on closeStack
  put the short name of this stack into sName
  if sName <> "mc" then 
    answer "Do you want to save this stack?" with "yes" or "no"
    if it is "yes" then save this stack as stack myStack
  else
  end if
end if
end closeStack

The first "if" evaluates if it is the cloned or original stack (I don't want them saving to the original).  When the user closes their new stack, it asks them if they want to save the information.  This script does exactly what I want it to do.  I want the users to be able to repeatedly modify their new stack until they are ready to "finalize" it so that it cannot be changed.  

The users finalize the script from a different stack - a control stack.  The name of the user-created stacks are put into a field.  The user can select the name of the stack they want to finalize and press a "Prepare" button.  Here is the script for that button:

global selectTest

on mouseUp
  open card 2 stack selectTest
  do hideAll
  do deleteTcard
  do changeScript
end mouseUp

Selecting the appropriate stack name loads it into the global "selectTest".  The unecessary buttons and fields are hidden, and certain cards are removed.  The scripts are stack level again.  

In order to prevent future saving to this stack, I want to comment out the "on closeStack" portion of the stack script.  The "do changeScript" portion does not comment out the "on closeStack" of the target card, though.

Here is the "on changeScript" from the control card:

on changeScript
  put the script of this stack into tempScript
  repeat with i = 1 to the number of lines in tempScript
    if line i of tempScript = "on closeStack" then put "--" before line i of tempScript
  end repeat
  set the script of thisStack to tempScript
  save this stack
end changeScript

As I said, this part of the script doesn't work.  The Revolution documentation has a section entitled "How do I change a script at runtime?".  There is a section for changing a card script.  Can I even do this for a stack script?  I don't know if the script I wrote is a viable solution.  I also only commented out the "on changeScript" line.  That doesn't save to the target stack, though.

Any suggestions?

Thanks for any help,
Jason




More information about the use-livecode mailing list