Do scripts have an access to editor's context?

Hey guys!

I would like to add attribute which allows to choose tween easing function:

SomeScript.attributes.add('easing', {  
    type: 'string',
    enum: [
          { 'Linear': 'Linear' },
          { 'SineIn': 'SineIn' },

Obviously, that works fine.

But as soon as I want to add the same attribute to another script, I face a problem.
To avoid code repeating, it would be great to export enum’s content to some constant and use it by reference:

var Constants = pc.createScript('constants');

Constants.EASINGS = [
            { 'Linear': 'Linear' },
            { 'QuadraticIn': 'QuadraticIn' }           

and then use it everywhere:

AnotherScript.attributes.add('easingFunction', {  
    type: 'string',
    enum: Constants.EASINGS 

Sounds fine, right?
No. Everything works in the game, but not in the editor. Every time I click parse on the script, I get an error:

So the question is next: Is there any way to declare a variable which will be visible and accessible from both game’s and editor’s context?

Hi @Igor, indeed I can confirm that behavior.

I am 99% certain that when the editor parses a script to extract the script attributes it executes only the code included in the script.

So as far as editor attributes are concerned, unless something changes in the editor side, I think this isn’t doable.

In the game context, as you say, everything is being added to the webpage and you can easily have global variables shared between scripts, libraries defining global objects etc.

@will may be able to comment on this.

1 Like

There is a concern of having global relationship between scripts. Order of loading can have impact on them. When script is parsed in Editor (separate worker) for attributes parsing, it does not load all the other scripts that come before in loading order. So it does not know anything about other scripts.

This could be added, but that would slow down attributes parsing on large projects significantly.