Your first FL# script
You need the SDK in a world project (the NodeWorld SDK) and a scene with its NW World object (worlds). Nothing else: the SDK brings fluxc, the FL# compiler, and runs it with the .NET runtime that comes with the Unity Editor.
Make the scripts folder
- In the Project window (the Unity window that lists the files of your project), right-click the folder of your world, then Create, NodeWorld, FL# Scripts Folder.
- A
Fluxfolder appears there, with an assembly definition named after the folder you clicked: inAssets/Tavern, it isTavern.Flux.asmdef. Unity leaves the scripts of this folder alone:fluxccompiles them, against the FL# API.
Write the script
In the Flux folder, make a file Door.cs with your code editor (write FL# in your IDE):
using NodeWorld.Flux;
namespace Tavern
{
/// <summary>A door that opens when a player uses it, for everyone in the room.</summary>
public class Door : FluxScript
{
public float openAngle = 90f; // set from the scene
private bool _open;
protected override void Start() => Interaction.SetInteractable(gameObject, true);
protected override void OnInteract() => SendNetworkEvent(NetworkEventTarget.All, "Toggle");
protected override void OnNetworkEvent(string name, NetReader arguments, int senderId)
{
if (name != "Toggle") return;
_open = !_open;
transform.localRotation = Quaternion.Euler(0f, _open ? openAngle : 0f, 0f);
}
}
}OnInteract runs on the device of the player who uses the door; SendNetworkEvent with NetworkEventTarget.All runs OnNetworkEvent on every player's device, so the door turns for everyone.
Put it in the world
- Select the world's NW World Config and drag
Door.csinto its Flux Sharp Sources list. - Select the door in the scene: Add Component, NodeWorld, FL# Script.
- Click Read the scripts: the SDK compiles the world's scripts once and lists their classes. Pick
Tavern.Doorunder Script. - Give the door a Network Id (any name, unique in the world): network events and synced objects need one. Its fields show under it: set openAngle if 90 does not suit you.
Try it
Enter Play mode: the SDK compiles the world's scripts for your computer and runs them as the game does. Point at the door and use it.
A mistake in a script stops the build with fluxc's message in the Console: the file, the line and column, and the C# error, for example Door.cs(18,27): error CS1002: ; expected. Your code editor underlines the same errors as you type.
Publish
Open NodeWorld, World Publisher and click Build World (publish a world): the World Publisher compiles the scripts into one native module per platform and puts them in the world's folder. There is no compiler or path to set.
