BookmarkSubscribeRSS Feed
Highlighted
MattH

Occasional Contributor

Joined:

Oct 10, 2018

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

Joined:

Jun 23, 2011

Solution

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

Occasional Contributor

Joined:

Oct 10, 2018

Solution

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.

 

ANSWER.pngUn select: Use the "Here" namespace

7 REPLIES
MattH

Occasional Contributor

Joined:

Oct 10, 2018

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

Occasional Contributor

Joined:

Oct 10, 2018

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

Joined:

Jun 23, 2011

Solution

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

Occasional Contributor

Joined:

Oct 10, 2018

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

Joined:

Jun 23, 2011

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

Occasional Contributor

Joined:

Oct 10, 2018

Solution

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.

 

ANSWER.pngUn select: Use the "Here" namespace

Craige_Hales

Staff

Joined:

Mar 21, 2013

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

Capture.PNGchecked by default

Craige