A special Design, ProjectGlobals, allows Rule authors the ability to write "project global" functions that are callable throughout their project (and in projects that reference the project). The Design name ProjectGlobals is therefore reserved for use by Knowledge Bridge; a Design with that name will be used as described here, and it is an error to try to add mixins to it or use it as a mixin.
The ProjectGlobals Design does not get instantiated. It is merely a repository where authors can place properties or functions which they want to access from anywhere in their project. Any project that includes a ProjectGlobals Design will have those properties and functions, as well as any properties or functions defined in sub-projects.
We call Methods defined on ProjectGlobals "global functions." We call basic Rules written on ProjectGlobals "global properties."
The properties and functions on ProjectGlobals are not actually Rules. The Rule editing environment is used, but globals use only the formula of the Rule editor. The other behavior, flags, and semantics of Rules are not followed. For example, there are no dependencies created when globals are referenced. Changing a global in a session requires a full reset of the session, just as if sub-projects are changed. Most flags have no meaning. Lookup, Parameter, and so on do not apply. Globals are not cached; they run every time they are called.
It is not legal to reference model-relative data inside the formula of a global, because there is no "this" in a global. Globals may only reference other globals, or the arguments that get passed in (for Methods). You can make references to some methods on R. For example, you can get R.rootModel. You can make references to the JavaScript Math object.
As noted, all names of ProjectGlobals properties and methods get added to a single namespace. As a result, there is the possibility of name collisions with existing globals defined in subprojects. It is recommended that project-specific functions get named in project-identifiable ways. It is definitely not a good idea to use common function names, like sort, first, sqrt, and so on.
To use ProjectGlobals:
1.Add a ProjectGlobals Design to your project. The name must be exactly ProjectGlobals.
2.Add any Rules or Methods on ProjectGlobals that you want to be globally accessible.
3.Anywhere you want to call your global, use the call R.globals.<ruleOrMethodName>(<arguments if method).
A property global is like a basic rule, and is referenced without using parentheses:
R.globals.MyProjectVersion
The definition of a global property should not set any flags; they are ignored anyway.
A function global reference uses parentheses like a method call:
R.globals.MyProjectSpecialCalc(this.x, this.y, this.z)
The definition of a global function must use the Method flag.