What is your best practice for setting a script in a script?

Paul Dupuis paul at researchware.com
Sat Jul 15 11:06:09 EDT 2023


So in the instances where you have a script that creates an object and 
then sets the script of that object (example below), what is you best 
practice for having the script in a script and still be readable?

Example:
BUTTON "Make"
on mouseUp
   local tScript
   create button "Sample"
   put "on mouseUp"&cr into tScript
   put "  ask 'Please enter a number between 1 and 100'" &cr after tScript
   put "  if it is not a number then exit mouseUp" &cr after tScript
   put "  if it < 1 OR it > 100 then exit mouseUp" &cr after tScript
   put "  put it into field 'Number'" &cr after tScript
   put "end mouseUp" after tScript
   replace "'" with quote in tScript
   set the script of button "Sample" to tScript
end mouseUp

This create a button "Sample" with the script
on mouseUp
   ask "Please enter a number between 1 and 100"
   if it is not a number then exit mouseUp
   if it < 1 OR it > 100 then exit mouseUp
   put it into field "Number"
end mouseUp

However, I reading the script for button Sample in button Make with the 
"pu" statements and quotes (double and single) and cr and so one 
cumbersome to read. Yes there are behavior scripts, but this is about 
the best practice of placing a script in a script (to set the script of 
an object) and having it as clear as possible.

I wish there was a command like "put begin block" where you could follow 
it any  number of lines and then "end block into tVar". i.e.

put begin block
on mouseUp
   ask "Please enter a number between 1 and 100"
   if it is not a number then exit mouseUp
   if it < 1 OR it > 100 then exit mouseUp
   put it into field "Number"
end mouseUp
end block into tScript

Is there a better way to have a script written in a script?




More information about the use-livecode mailing list