-
Notifications
You must be signed in to change notification settings - Fork 0
Routines
We call user generated code "routines" and they are written in whatever language is native to your game engine. As of Apr 2, 2024, we only support Unity (C#), but we're going to be working on an Unreal plugin soon.
I know we just said C#, but actually we've added some features and removed others.
We've removed loops, class definitions, asynchronous code, and more. The idea is you're not meant to implement complex functionality directly within GameScript, but you can call out to complex logic you've written elsewhere. We may unlock further functionality depending on demand.
The main addition we've added to C# (and any other languages to come) is the concept of "scheduled blocks". A scheduled block is a chunk of code that sits between an "entry arrow" and an "exit arrow". Here's a simple scheduled block.
<-
Debug.Log("This code is inside a scheduled block.");
->
Right now, this block will immediately execute causing a string to be logged to console. But you can also add "entry flags" and "exit flags" to the "entry arrow" and "exit arrow". These are boolean flags that your scheduled blocks can wait for before executing, and/or set after execution has completed.
Here's a more complicated example with two scheduled blocks that both make use of flags.
<-
Debug.Log("This executes first");
-FirstDone>
<FirstDone-
Debug.Log("This executes after the FirstDone flag is set");
->
As you can see, these blocks of code will execute in sequence. The first block executes, and then sets a flag called "FirstDone". Once "FirstDone" is set, the second scheduled block will execute.
The @lease keyword is used to send your code a reference to a lease. Leases are used to prevent a scheduled block from firing off its exit flags. It won't set it's exit flags until you've released the lease.
Note: @lease only works inside of scheduled blocks.
Here's an even more complex example of a series of scheduled blocks that use leases to control the flow of execution.
<-
Debug.Log("This executes first");
-FirstDone>
<FirstDone-
Debug.Log("This executes after the FirstDone flag is set");
Debug.Log("It also calls a function written elsewhere that takes in a lease as an");
Debug.Log("argument and presumably waits 5 seconds before releasing it.");
HoldLeaseForSeconds(@lease, 5);
-SecondDone>
<SecondDone,FirseDone-
Debug.Log("This executes after the FirstDone and SecondDone flags are set");
Debug.Log("That's right, you can wait for or set multiple flags at once using");
Debug.Log("a comma separated list within entry and exit arrows.");
->
We've also added the @node keyword with can send your code a reference to the current node being executed.
<-
LookAtNode(@node);
->
Each game engine plugin we write will have the concept of a "flag bus" for each conversation being executed. With the flag bus, you can set flags outside of an executing routine so that your routines can wait for external events to occur before proceeding.