<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Run Script - OK versus Add-In Script Not OK in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Run-Script-OK-versus-Add-In-Script-Not-OK/m-p/476524#M72101</link>
    <description>&lt;P&gt;JSL is unlike many other programming languages in that it doesn't do automatic scope control like, say, Python might.&amp;nbsp; In this case you're using the line&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;(test &amp;lt;&amp;lt; top parent)[listboxbox( 1 )] &amp;lt;&amp;lt; set script(...&lt;/CODE&gt; to add a script to the list box.&amp;nbsp; When this script does run (by the user selecting an item), then any variable within that script must be resolved -- this is where the scope comes in.&amp;nbsp; In Python each function has a local scope and each scope is aware of it's parent scope and the global scope (and scopes are persistent), such that a variable in a function can access variables in the parent scope or global scope.&amp;nbsp; JSL does not do this -- functions don't create and remember scopes and any scope that is created does not keep a record of the scope that created it.&amp;nbsp; For JSL, when an unscoped variable is accessed (either by &lt;CODE class=" language-jsl"&gt;namespace:variable&lt;/CODE&gt; or &lt;CODE class=" language-jsl"&gt;As Scoped( namespace, variable )&lt;/CODE&gt; then it will by default go to the &lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; or global scope and that is it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Scope lookup for unscoped names is something like this:&amp;nbsp; Look at the local namespace if it exists (if you're in a &lt;CODE class=" language-jsl"&gt;Local( {}, ... )&lt;/CODE&gt; function or &lt;CODE class=" language-jsl"&gt;Function( {}, {Default Local}, ...&amp;nbsp;)&lt;/CODE&gt; function are the most common), look at the &lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; namespace (if it exists), look at the global namespace.&amp;nbsp; Sometimes it looks at column names (such as in a &lt;CODE class=" language-jsl"&gt;For Each Row()&lt;/CODE&gt; function).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your file you don't use any auto-scoping shortcuts (such as &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt;), so each variable is globally scoped.&amp;nbsp; Thus, when the &lt;CODE class=" language-jsl"&gt;List Box&lt;/CODE&gt; script runs it can find &lt;CODE class=" language-jsl"&gt;test&lt;/CODE&gt; because it looks in the global scope.&amp;nbsp; However, addin scripts by default utilize the &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt; function &lt;EM&gt;whether or not&lt;/EM&gt; it's in the script file.&amp;nbsp; Under this scoping, the files&amp;nbsp;&lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; namespace is deleted once the script finishes, and the &lt;CODE class=" language-jsl"&gt;List Box&lt;/CODE&gt; script cannot find &lt;CODE class=" language-jsl"&gt;test&lt;/CODE&gt; in any scope that it has access to (namely, it's own &lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; namespace and the global namespace).&amp;nbsp; You can turn off the &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt; in the addin version, but I recommend against this and it's better to explicitly control the scope.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That said, to disable&amp;nbsp;the &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt; in the addin version, uncheck the following box:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ErraticAttach_0-1649228861770.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/41558i6D70505D7D545B72/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ErraticAttach_0-1649228861770.png" alt="ErraticAttach_0-1649228861770.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Apr 2022 07:11:39 GMT</pubDate>
    <dc:creator>ErraticAttack</dc:creator>
    <dc:date>2022-04-06T07:11:39Z</dc:date>
    <item>
      <title>Run Script - OK versus Add-In Script Not OK</title>
      <link>https://community.jmp.com/t5/Discussions/Run-Script-OK-versus-Add-In-Script-Not-OK/m-p/476403#M72094</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to the fellow board users, I have a script working that includes column switchers and local data filters. The script works as intended and the next step is I wanted to package as an add-in for the client base. &amp;nbsp;I think I details of the add-in working and I can launch the script and it goes through the data import, clean up and summarization and makes the interface. &amp;nbsp;HOWEVER, the interface is now giving me errors when I try to execute the column switcher that worked fine if I launch the script by itself. If I click on a new item in the column switcher I get the following error I have attached the code than creates this view. &amp;nbsp;In my code I attach this to a summary data table and then execute it from within the script. If I run via add-in (where I just attached the script) it gives error. If I then close that window and click the button on the data table build the same display it works as intended without errors. So I am a bit confused as what I should change and insights?&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hegedus1_0-1649196193060.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/41523iF4F532D979902043/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hegedus1_0-1649196193060.png" alt="Hegedus1_0-1649196193060.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;cell_sum &amp;lt;&amp;lt; new script(
	"Main Interface",
	cell_sum = Current Data Table();
	test = Fit Group(
		Oneway(
			Y( :Max Discharge Capacity ),
			X( :Cathode Recipe.x ),
			Quantiles( 1 ),
			Means( 1 ),
			Box Plots( 1 ),
			Mean Diamonds( 0 ),
			X Axis Proportional( 0 ),
			Points Jittered( 1 ),
			Grand Mean( 0 ), 
		
		), 
	
		Oneway(
			Y( :"Cycle Number (&amp;gt;0.8)"n ),
			X( :Cathode Recipe.x ),
			Quantiles( 1 ),
			Means( 1 ),
			Box Plots( 1 ),
			Mean Diamonds( 0 ),
			X Axis Proportional( 0 ),
			Points Jittered( 1 ),
			Grand Mean( 0 ), 
		
		),
		Oneway(
			Y( :"Discharge Capacity @ 50 Cycles"n ),
			X( :Cathode Recipe.x ),
			Quantiles( 1 ),
			Means( 1 ),
			Box Plots( 1 ),
			Mean Diamonds( 0 ),
			X Axis Proportional( 0 ),
			Points Jittered( 1 ),
			Grand Mean( 0 ), 

		),
		Oneway(
			Y( :"Remain % @ 50 Cycles"n ),
			X( :Cathode Recipe.x ),
			Quantiles( 1 ),
			Means( 1 ),
			Box Plots( 1 ),
			Mean Diamonds( 0 ),
			X Axis Proportional( 0 ),
			Points Jittered( 1 ),
			Grand Mean( 0 ), 
		
		), 

		&amp;lt;&amp;lt;{Arrange in Rows( 4 )}
	);
	colpick = test &amp;lt;&amp;lt; Column Switcher(
		:Cathode Recipe.x,
		cell_sum &amp;lt;&amp;lt; get column names( Ordinal, Nominal )
	

	);
	(test &amp;lt;&amp;lt; top parent)[listboxbox( 1 )] &amp;lt;&amp;lt; set script(
		Try( test &amp;lt;&amp;lt; remove local data filter );
		mycurrent = ((test &amp;lt;&amp;lt; top parent)[listboxbox( 1 )] &amp;lt;&amp;lt; get selected)[1];
		test &amp;lt;&amp;lt; Local Data Filter(
			Add Filter( columns( Column( mycurrent ) ), Display( Column( mycurrent ), N Items( 15 ), Find( Set Text( "" ) ) ) )
		);
	);
		
	test &amp;lt;&amp;lt; Local Data Filter(
		Add Filter( columns( colpick &amp;lt;&amp;lt; get current ), Display( colpick &amp;lt;&amp;lt; get current, N Items( 15 ), Find( Set Text( "" ) ) ) )
	);
);
cell_sum &amp;lt;&amp;lt; run script( "Main Interface" );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:56:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Run-Script-OK-versus-Add-In-Script-Not-OK/m-p/476403#M72094</guid>
      <dc:creator>Hegedus1</dc:creator>
      <dc:date>2023-06-09T16:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Run Script - OK versus Add-In Script Not OK</title>
      <link>https://community.jmp.com/t5/Discussions/Run-Script-OK-versus-Add-In-Script-Not-OK/m-p/476524#M72101</link>
      <description>&lt;P&gt;JSL is unlike many other programming languages in that it doesn't do automatic scope control like, say, Python might.&amp;nbsp; In this case you're using the line&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;(test &amp;lt;&amp;lt; top parent)[listboxbox( 1 )] &amp;lt;&amp;lt; set script(...&lt;/CODE&gt; to add a script to the list box.&amp;nbsp; When this script does run (by the user selecting an item), then any variable within that script must be resolved -- this is where the scope comes in.&amp;nbsp; In Python each function has a local scope and each scope is aware of it's parent scope and the global scope (and scopes are persistent), such that a variable in a function can access variables in the parent scope or global scope.&amp;nbsp; JSL does not do this -- functions don't create and remember scopes and any scope that is created does not keep a record of the scope that created it.&amp;nbsp; For JSL, when an unscoped variable is accessed (either by &lt;CODE class=" language-jsl"&gt;namespace:variable&lt;/CODE&gt; or &lt;CODE class=" language-jsl"&gt;As Scoped( namespace, variable )&lt;/CODE&gt; then it will by default go to the &lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; or global scope and that is it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Scope lookup for unscoped names is something like this:&amp;nbsp; Look at the local namespace if it exists (if you're in a &lt;CODE class=" language-jsl"&gt;Local( {}, ... )&lt;/CODE&gt; function or &lt;CODE class=" language-jsl"&gt;Function( {}, {Default Local}, ...&amp;nbsp;)&lt;/CODE&gt; function are the most common), look at the &lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; namespace (if it exists), look at the global namespace.&amp;nbsp; Sometimes it looks at column names (such as in a &lt;CODE class=" language-jsl"&gt;For Each Row()&lt;/CODE&gt; function).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your file you don't use any auto-scoping shortcuts (such as &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt;), so each variable is globally scoped.&amp;nbsp; Thus, when the &lt;CODE class=" language-jsl"&gt;List Box&lt;/CODE&gt; script runs it can find &lt;CODE class=" language-jsl"&gt;test&lt;/CODE&gt; because it looks in the global scope.&amp;nbsp; However, addin scripts by default utilize the &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt; function &lt;EM&gt;whether or not&lt;/EM&gt; it's in the script file.&amp;nbsp; Under this scoping, the files&amp;nbsp;&lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; namespace is deleted once the script finishes, and the &lt;CODE class=" language-jsl"&gt;List Box&lt;/CODE&gt; script cannot find &lt;CODE class=" language-jsl"&gt;test&lt;/CODE&gt; in any scope that it has access to (namely, it's own &lt;CODE class=" language-jsl"&gt;Here&lt;/CODE&gt; namespace and the global namespace).&amp;nbsp; You can turn off the &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt; in the addin version, but I recommend against this and it's better to explicitly control the scope.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That said, to disable&amp;nbsp;the &lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 )&lt;/CODE&gt; in the addin version, uncheck the following box:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ErraticAttach_0-1649228861770.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/41558i6D70505D7D545B72/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ErraticAttach_0-1649228861770.png" alt="ErraticAttach_0-1649228861770.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 07:11:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Run-Script-OK-versus-Add-In-Script-Not-OK/m-p/476524#M72101</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-04-06T07:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Run Script - OK versus Add-In Script Not OK</title>
      <link>https://community.jmp.com/t5/Discussions/Run-Script-OK-versus-Add-In-Script-Not-OK/m-p/476673#M72114</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your complete description of what was happening and the explanation of namespaces.&lt;/P&gt;&lt;P&gt;I really didn't fully grasp what "Names Default to Here (1)" really was about. &amp;nbsp;Learned something new.&lt;/P&gt;&lt;P&gt;Thank you again.&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 13:44:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Run-Script-OK-versus-Add-In-Script-Not-OK/m-p/476673#M72114</guid>
      <dc:creator>Hegedus1</dc:creator>
      <dc:date>2022-04-06T13:44:51Z</dc:date>
    </item>
  </channel>
</rss>

