Import System for Project Scripts in Perspective?

Total Perspective noob here, I finally got to mess around some last night for my home automation project. I wrote a project script ecobee.getTokens() which contains a tag reading line. When I tried to run the script from the script console in the designer, it gave me Global name system not found. I had to add import system to get the script to work. Is this normal?

From my point of view, this is not a noob question. Anyone who can answer this fully has mastered the dark arts of Ignition. I’ve researched and asked related questions in the past and still don’t understand.

I’m jumping on this thread to say I’m still hoping to learn more in this area, and so I get notified of any replies.

:+1:

(EDIT: To answer your simplest surface question, I’ve found I get the best behavior if I never import any of my own custom script libraries, and only import system when working in the scripting console. Which sometimes requires editing my script files to have import system while working in designer, but then not saving the change…)

1 Like

Without seeing exactly you’re doing in your ecobee.getTokens() method, it’s difficult to say why the script console was throwing a global name error. That said, I have never had any Global name errors thrown when using system.* methods in my scripts.

I’ll invoke Cunningham’s law; we’ll see if Phil has any clarifications to make, but:

import system should be required in exactly one area - when defining a function inside gateway event scripts, which still use legacy scoping rules. In all other areas, both system libraries and your project libraries should be automatically available.

1 Like

I can say from experience that avoiding imports works fine in every case except sometimes the Designer script console, which will randomly fail for system not being defined. In those cases I temporarily add import system to the script throwing the error, but don’t save it, and the script console will start working.

It definately isn’t anything in my script, its just barely a few lines, read a tag, httpPost, jsonDecode and tag write. Besides, I wrote the script in the console and it ran like a champ. Moved it to a Project Script and bam, system global not found. Add import system, and works again.

This is my first time seeing this. My production server is still on v7.9