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

Mark Smith marksmithhfx at gmail.com
Sat Jul 15 16:16:37 EDT 2023


Another possibility, which is sort of a combination of Alex and Dicks suggestions is to create a “scripts” card and store all of the scripts as readable custom properties. When I have done this in the past I typically just number the scripts (cScript1 … cScriptn) and put some metadata in the first line of each. Usually a comment of the form "—cScript1 — button Sample of cd X". If you do that, when you list the custom properties of the scripts in the property inspector you see the metadata along with each cp field name (so it would look like, cScript1 — cScript1 — button Sample of cd X) and you can see a whole list of them. In this situation, the code you provided would be replaced with:

create button “Sample”
set the script of btn “Sample” to the cScript1 of cd “Scripts"
Mark


> On 15 Jul 2023, at 4:06 pm, Paul Dupuis via use-livecode <use-livecode at lists.runrev.com> 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