cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
MattH
Level II

How can you use Global Variables with Encrypted Scripts

Using an encrypted script in Jmp13, I would like to read up a pre-assigned global variable. 

Example:

With a standard script assign...

a=0;
b=10;

Using an Encrypted script

if (IsEmpty(a)==1,a=5);  // DO NOTHING IF ITS NOT EMPTY
if (IsEmpty(b)==1,b=50);  // DO NOTHING IF ITS NOT EMPTY
Write(a);
Write(b);

Goal:  If the global variable is undefined, assign it in the encrypted script.  If the global variable is defined, use the defination.

 

It works without encryption.  Also, after executing the encrypted script, I can see the assigned defaulted globals.

So, is it possible to use a global variable with an encrypted script?

Thanks for the help.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: How can you use Global Variables with Encrypted Scripts

I believe this is an issue of scoping and namespaces, and the fact that the add-in menu uses Names Default to Here(1).

 

If you're trying to reference variables you should always use a scoping operator to reference them. The scoping operator for global variables is ::.

 

names default to here(1);

::a=0;

a=45;


if(::a==0, show("yes"));

if(here:a == 45, show("yes"));
-Jeff

View solution in original post

MattH
Level II

Re: How can you use Global Variables with Encrypted Scripts

ANSWER ==> Un click the "Use the "Here" namespace for unqualified JSL variable names

It works for standard add-in script and for encrypted scripts.

 

Un select:  Use the "Here" namespaceUn select: Use the "Here" namespace

View solution in original post

7 REPLIES 7
MattH
Level II

Re: How can you use Global Variables with Encrypted Scripts

Clarification. The issue lies within using the encrypted script in an add-in.
Just confirmed that it works with encryption as a stand alone script.
So does the add-in operate on a different variable space? Odd, as I can see other variables from encrypted scripts in this add-in
Apologies for not debugging this completely.
MattH
Level II

Re: How can you use Global Variables with Encrypted Scripts

Further Clarification: The issue is not with encryption, but with the add-in. Using the jsl directly in the add in causes the same issue. The global variables are not seen by the add-in
Jeff_Perkinson
Community Manager Community Manager

Re: How can you use Global Variables with Encrypted Scripts

I believe this is an issue of scoping and namespaces, and the fact that the add-in menu uses Names Default to Here(1).

 

If you're trying to reference variables you should always use a scoping operator to reference them. The scoping operator for global variables is ::.

 

names default to here(1);

::a=0;

a=45;


if(::a==0, show("yes"));

if(here:a == 45, show("yes"));
-Jeff
MattH
Level II

Re: How can you use Global Variables with Encrypted Scripts

Jeff, thanks for the confirmation. Yes, I agree. It's a scoping issue. However, the solution is to uncheck that box in the add-in. This allows the outside script to set a global, and the internal add-in to use it. I wish I could have found that in one of the guides. Oh well.
Jeff_Perkinson
Community Manager Community Manager

Re: How can you use Global Variables with Encrypted Scripts

Well, you and @Craige_Hales are right that unchecking the "Use the Here namespace..." option in the add-in builder will resolve your specific issue.

 

However, I'm sure that @Craige_Hales would agree with me that the better programming/scripting practice is to properly scope all variables as you reference them.

 

The "Use the Here namespace..." option is on by default in order to protect the global namespace from accidental corruption.

-Jeff
MattH
Level II

Re: How can you use Global Variables with Encrypted Scripts

ANSWER ==> Un click the "Use the "Here" namespace for unqualified JSL variable names

It works for standard add-in script and for encrypted scripts.

 

Un select:  Use the "Here" namespaceUn select: Use the "Here" namespace

Craige_Hales
Super User

Re: How can you use Global Variables with Encrypted Scripts

I think this will get you close to the answer; it looks like the default is to use the Here namespace in an addin, so you might need to use global:a rather than a

checked by defaultchecked by default

Craige