Class Script
- Namespace
- LunyScript /
- Assembly
- LunyScript.dll
Abstract base class for all LunyScripts. Provides the API interface for beginner-friendly block-based scripting in C#. Inherit from this class and implement its Build() method to construct script logic.
public abstract class Script
Expand Details ...
- Inheritance
-
ObjectScript
- Derived
Remarks
Minimal example script:
public class Example : LunyScript.Script
{
public override void Build(ScriptContext context)
{
// Define behaviour using declarative LunyScript API here ...
On.Ready(Debug.Log("Hello, LunyScript!"));
}
}
To run this script, create a GameObject in the scene and name it 'Example' - same as the script. In the future alternative script assignment options will be provided.
Constructors
Script()
protected Script()
Properties
Component
public ComponentApi Component { get; }
Property Value
Debug
public DebugApi Debug { get; }
Property Value
Editor
public EditorApi Editor { get; }
Property Value
GVar
Global variables
public ScriptVariables GVar { get; }
Property Value
Input
public InputBuilder Input { get; }
Property Value
IsEditor
True if the script currently runs within the engine's editor (play mode). False in builds.
public Boolean IsEditor { get; }
Property Value
- Boolean
Name
public String Name { get; }
Property Value
- String
Object
public ObjectBuilder Object { get; }
Property Value
On
public OnObjectEventBuilder On { get; }
Property Value
Prefab
public PrefabBuilder Prefab { get; }
Property Value
Scene
public SceneApi Scene { get; }
Property Value
Self
Reference to script's engine object.
protected ILunyObject Self { get; }
Property Value
Time
public TimeApi Time { get; }
Property Value
Transform
public TransformBuilder Transform { get; }
Property Value
Var
Instance variables (unique per script/object)
public ScriptVariables Var { get; }
Property Value
When
public WhenGlobalEventBuilder When { get; }
Property Value
Methods
AND(params ConditionBlock[])
Logical AND: Returns true if all conditions are true. Requires at least two conditions.
public ConditionBlock AND(params ConditionBlock[] conditions)
Parameters
| Type | Name | Description |
|---|---|---|
conditions |
Returns
Build(ScriptBuildContext)
Called once when the script is initialized. Users construct their blocks (sequences, statemachines, behaviors) for execution here. Users can use regular C# syntax (ie call methods, use loops) to construct complex and/or reusable blocks.
public abstract void Build(ScriptBuildContext context)
Parameters
| Type | Name | Description |
|---|---|---|
context |
Check(Func<IScriptRuntimeContext, Boolean>)
Executes a System.Func<IScriptRuntimeContext, bool> (lambda) or method taking a IScriptRuntimeContext parameter and returns bool.
public ConditionBlock Check(Func<IScriptRuntimeContext, Boolean> func)
Parameters
| Type | Name | Description |
|---|---|---|
func |
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Check" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
Check(Func<Boolean>)
Executes a System.Func<bool> (lambda) or parameterless method returning bool.
public ConditionBlock Check(Func<Boolean> func)
Parameters
| Type | Name | Description |
|---|
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Check" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
Coroutine(String)
Creates a named coroutine. Usage: Coroutine("name").Duration(3).Seconds().OnUpdate(blocks).Elapsed(blocks);
public CoroutineBuilder Coroutine(String name)
Parameters
| Type | Name | Description |
|---|---|---|
name |
Returns
~Script()
protected ~Script()
For(VariableBlock)
For loop (1-based index): For(numberOfTimes).Do(blocks); Starts at 1 and increments by 1 until limit is reached (inclusive).
public ForBlockBuilder For(VariableBlock numberOfTimes)
Parameters
| Type | Name | Description |
|---|---|---|
numberOfTimes |
Returns
For(VariableBlock, VariableBlock)
For loop (1-based index): For(limit, step).Do(blocks); If step is positive: starts at 1 and increments by step until limit is reached. If step is negative: starts at limit and decrements by step until 1 is reached.
public ForBlockBuilder For(VariableBlock numberOfTimes, VariableBlock step)
Parameters
| Type | Name | Description |
|---|---|---|
numberOfTimes |
||
step |
Returns
If(params ConditionBlock[])
Conditional execution: If(conditions).Then(blocks).ElseIf(conditions).Then(blocks).Else(blocks); Multiple conditions are implicitly AND combined.
public IfBlock If(params ConditionBlock[] conditions)
Parameters
| Type | Name | Description |
|---|---|---|
conditions |
Returns
NOT(ConditionBlock)
Logical NOT: Returns the inverse of the condition.
public ConditionBlock NOT(ConditionBlock condition)
Parameters
| Type | Name | Description |
|---|---|---|
condition |
Returns
OR(params ConditionBlock[])
Logical OR: Returns true if at least one condition is true. Requires at least two conditions.
public ConditionBlock OR(params ConditionBlock[] conditions)
Parameters
| Type | Name | Description |
|---|---|---|
conditions |
Returns
Run(Action)
Executes a System.Action (lambda) or parameterless method returning void.
public ActionBlock Run(Action action)
Parameters
| Type | Name | Description |
|---|---|---|
action |
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Run" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
// A lambda adds notable 'syntax noise':
On.Ready(Run(() => LunyLogger.LogInfo("custom log inline")));
// Multi-line lambdas are even worse:
On.Ready(Run(() => {
LunyLogger.LogInfo("custom log inline");
}));
// A named method is much cleaner, and re-usable:
On.Ready(Run(MyCustomLog));
internal static void MyCustomLog() {
LunyLogger.LogInfo("custom log");
}
Run(Action<IScriptRuntimeContext>)
Executes a System.Action (lambda) or a method that takes a IScriptRuntimeContext parameter and returns void.
public ActionBlock Run(Action<IScriptRuntimeContext> action)
Parameters
| Type | Name | Description |
|---|---|---|
action |
Returns
Remarks
- Intended for quick prototyping and testing.
- Prefer to convert "Run" code into a custom IBlock class after its initial development and testing,
- Prefer named methods over lambdas to ensure the block-based code continues to read like intent.
ToString()
public override String ToString()
Returns
- String
While(params ConditionBlock[])
Loop execution: While(conditions).Do(blocks); Multiple conditions are implicitly AND combined.
public WhileBlockBuilder While(params ConditionBlock[] conditions)
Parameters
| Type | Name | Description |
|---|---|---|
conditions |