Skip to content

Commit ea87484

Browse files
committed
Document undef
1 parent 1bf7daf commit ea87484

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

Doc/Reference/Constants-and-logging.md

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ loop.cont()
4343
impending.done() // will not compile since 'impending' never succeeds
4444
```
4545

46+
## Using `undef()`
47+
48+
If you defer implementing a status function, use `undef`:
49+
50+
```cs
51+
status Defend() => undef();
52+
```
53+
54+
Release and optimized builds do not support `undef`; this ensures your product is feature-complete before shipping.
55+
56+
By default `undef` returns the failing status; this may be customized:
57+
58+
```cs
59+
status Defend() => undef(cont); // with Active.Raw
60+
status Defend() => undef(cont()); // with Active.Status
61+
```
62+
4663
## Expression wrappers
4764

4865
Via `Active.Raw` or `Active.Status`, use a wrapper to include any expression within a status expression, then return an arbitrary status constant; here is an example:

README.md

+13-15
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,23 @@ Active Logic seamlessly integrates with C#:
1919
```cs
2020
class Duelist : UTask{
2121

22-
float health = 100;
23-
24-
Transform threat => null;
22+
float health = 100;
23+
Transform threat;
2524

2625
// BT selectors and sequences via || and &&
27-
override public status Step() => Attack() || Defend() || Retreat();
26+
override public status Step()
27+
=> Attack()
28+
|| Defend()
29+
|| Retreat();
2830

2931
// Conditionals without 'conditional nodes'
30-
status Attack() => threat && health > 25
31-
? Engage(threat) && Cooldown(1.0f)?[ Strike(threat) ]
32-
: fail(log && $"No threat, or low hp ({health})");
33-
34-
// Special statuses (pending, impending, action, ...) are useful
35-
// when you know a task will never fail, never succeed or similar.
36-
// (optional but type safe!)
37-
pending Defend() => + undef();
38-
status Engage(Transform threat) => undef();
39-
impending Retreat() => - undef();
40-
action Strike(Transform threat) => @void();
32+
status Attack() => (threat && health > 25) ?
33+
Engage(threat) && Cooldown(1.0f)?[ Strike(threat) ]
34+
: fail(log && $"No threat, or low hp ({health})");
35+
36+
status Defend() => ...;
37+
38+
// ...
4139
4240
}
4341
```

0 commit comments

Comments
 (0)