-
Notifications
You must be signed in to change notification settings - Fork 0
Scripting Sample
Pixxl edited this page Nov 28, 2019
·
5 revisions
Scripting in the Crystal Clear Engine is elegant and quick. Following is a baic example of a Hello-World program written in C# and designed for the Crystal Clear engine.
using CrystalClear.ScriptingEngine;
using CrystalClear.ScriptUtilities;
using CrystalClear.Standard.Events;
using CrystalClear.Standard.HierarchyObjects;
using CrystalClear.HierarchySystem;
[IsScript] // The IsScript attribute ensures that this class is categorized as a script.
public class HelloWorldExample : HierarchyScript<ScriptObject> // Inherit from HierarchyScript<ScriptObject> to "mark" this as a script applicable to the ScriptObjects. If we change the type parameter of the HierarchyScript to, for instance HierarchyObject, then we will be able to apply this to any HierarchyObject. For the purposes of this script, the typeparameter does not matter.
{
[OnStartEvent] // Using any attribute that derives from the SubscribeAttribute is intended to subscribe the method to the provided event. This will also work on any static method by letting the code post processor analyze the generated assembly. This process is automatic. If an incompatible method has the attribute it will not work. OnStart will execute when the HierarchyScript is added to a HierarchyObject or when the HierarchyObject or Hierarchy are activated.
public void OnStart()
{
Output.Log("Hello World"); // Use the Output.Log method to print HelloWorld to the console or output.
Output.Log(HierarchyObject.Name); // Output the name of the HierarchyObject that this script is attatched to.
Output.Log(HierarchyObject.GetType()); // This will be the same as the type parameter provided to HierarchyScript or possibly a derivative of said type.
}
}