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

Paul Dupuis paul at researchware.com
Sat Jul 15 16:29:27 EDT 2023


All good suggestions so far, but not what I was after, which was whether 
there is any better way to have the script you are setting the newly 
created object to, readable, in the script that setup of the new object. 
If a behavior script is used or properties or objects then I can not 
read (and potentially revise) the script right in the script that is 
making the object. I have to open something else if I want to revise the 
script. Of course I can have a comment that says "look here for the 
script" and it is generally obvious from "set the script of button 
"Sample" to <some property and/or object reference>.



On 7/15/2023 11:06 AM, Paul Dupuis via use-livecode wrote:
> 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?
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your 
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list