Get started
Coming from Blueprints
If you have built with Blueprint graphs, you already know what Loom does. Each node you would place has a line of Loom that does the same thing.
Execution runs from the top of a function to the bottom, one statement per line, so there are no white execution wires to draw. Values that flow along data wires become arguments and variables.
The Blueprint itself
Section titled “The Blueprint itself”- Event
- Function call
- Flow control
- Variable
- Pure
var Count: int = 0In the My Blueprint panel. editable makes it Instance Editable, and private ticks Private.
fn Square(x: int) -> int { return x * x}fn Hit(amount: int, times: int = 1) -> int { return amount * times}A call that leaves it out gets the default, like an input’s default value in the Details panel:
Hit(5) is Hit(5, 1).
fn Lookup(key: string, out found: bool, out value: int) { found = key == "a" value = 1}A call gives the outputs back by name: let r = Lookup("a"), then r.found.
private pure fn Area() -> int { return Width * Height}pure makes a node with no exec pins, as the Pure checkbox does. private and protected set its
Access Specifier.
fn AddPoints(points: int) { Count = Count + points}Write it as a function, and call it wherever the macro or collapsed graph was.
blueprint BPL_Math : BlueprintFunctionLibrary at /Game/BPL_Math
pure fn Double(x: int) -> int { return x * 2}Any Blueprint calls it as BPL_Math.Double(4). See Function libraries.
dispatcher Scored(points: int)component Sound: AudioComponentOnly in an actor’s Blueprint.
interface BPI_Interactable at /Game/BPI_Interactable { fn Interact(by: Actor) fn CanInteract(by: Actor) -> bool}An interface is its own asset too, so it gets its own source file, with one function per line and
no bodies. A Blueprint that implements it handles each function with on.
implements BPI_Interactable
on Interact(by: Actor) { Open = !Open}One implements line per interface, after the header. Its functions are ordinary on handlers.
if implements(thing, BPI_Interactable) { cast(thing, BPI_Interactable).Interact(by)}implements(…) is Does Implement Interface. A call through cast(…) is the message: on an object
without the interface, it does nothing.
struct S_Cell at /Game/Types/S_Cell { X: int Y: int = 1 Visited: bool}A struct is its own asset, so it gets its own source file. Fields are listed one per line, each
starting at zero or at its default. Code makes one as S_Cell(X: 2) and reads cell.Y.
enum E_Tool at /Game/Types/E_Tool { Hammer Saw "Hand Saw" Chisel}An enum is its own asset, so it gets its own source file. Values are listed one per line. A label in
quotes is what the editor shows, and code uses the name: E_Tool.Saw.
Events
Section titled “Events”on ReceiveBeginPlay { Sum(100)}Events use their function name in the engine, here ReceiveBeginPlay.
event Pulse(times: int) { for i in 1..times { Lit = !Lit KismetSystemLibrary.Delay(0.5) }}Called like a function: Pulse(3).
Scored.broadcast(100)Sound.OnAudioFinished.bind(Finished)Sound.OnAudioFinished.unbind(Finished)Scored.unbind_all()KismetSystemLibrary.K2_SetTimerDelegate(other.K2_DestroyActor, 5.0, false)Name the function where an event is expected: one of this Blueprint’s, such as Blink, or another
object’s.
Loom is single-player for now: variables don’t replicate, and events can’t run on the server or on clients.
if x < 0 { return -1} else { return 1}The condition must be a bool.
while i <= n { i = i + 1}for i in 1..10 { total = total + i}Counts from the first number to the last, both included, as ForLoop does.
for name in Names {}for key, value in map walks a map.
for v in values { if v < 0 { break }}break leaves the loop, like the Break pin. continue skips to the next pass, which no Blueprint
node does. Both work in any loop.
match count { 0 { Hide() } 1, 2 { ShowFew() } else { ShowMany() }}The first arm that lists the value runs. Strings, names and enums work the same way. See match.
let speed = if running { 600.0 } else { 300.0 }Only the side chosen is computed. See If expressions.
return totalValues
Section titled “Values”Count = 1Count += 1Also -=, *=, /=, %=, &= and |=, on variables, fields, and array and map items.
let count = 3Lives + 1Calls KismetMathLibrary.Add_IntInt, as the node does.
cast(thing, Actor)Gives none when it isn’t one, instead of a Cast Failed pin.
["a", "b"]create_widget(WBP_Panel)KismetSystemLibrary.PrintString("hi")Any library function is called by its class and name.
Delays and timers
Section titled “Delays and timers”var Ready: bool = false
on ReceiveBeginPlay { KismetSystemLibrary.Delay(2.0) Ready = true}The handler pauses at the call and goes on once the wait is over. Only an event’s handler can wait. See Waiting.
var Lit: bool = false
on ReceiveBeginPlay { KismetSystemLibrary.K2_SetTimer(self, "Blink", 0.5, true)}
fn Blink() { Lit = !Lit}var Lit: bool = false
on ReceiveBeginPlay { KismetSystemLibrary.K2_SetTimerDelegate(Blink, 0.5, true)}
fn Blink() { Lit = !Lit}Loom has no timelines. Change the value a little on each Tick, or with a timer.
What works differently
Section titled “What works differently”- A pure node on its own does nothing, so a pure call on its own line is refused.
- A parameter cannot be assigned. Copy it into a
letfirst. - The graph Loom makes is not meant for editing: change the
.lmfile, and the next build remakes the graph.