Skip to content

Commit b647e14

Browse files
authored
Update Wurst agent language guidance (#79)
1 parent fcfbfc5 commit b647e14

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/kotlin/file/SetupApp.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object SetupApp {
3333

3434
private data class WurstProcessResult(val exitCode: Int, val output: List<String>)
3535

36-
internal const val AGENTS_TEMPLATE_VERSION = "2026-08-08"
36+
internal const val AGENTS_TEMPLATE_VERSION = "2026-08-29"
3737
private const val AGENTS_TEMPLATE_MARKER_PREFIX = "<!-- WURST_AGENTS_TEMPLATE_VERSION:"
3838
private const val AGENTS_TEMPLATE_MARKER = "<!-- WURST_AGENTS_TEMPLATE_VERSION: $AGENTS_TEMPLATE_VERSION -->"
3939
private const val AGENTS_TEMPLATE_SOURCE_HINT = "WurstScript Warcraft III map project notes"

templates/AGENTS.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- WURST_AGENTS_TEMPLATE_VERSION: 2026-08-08 -->
1+
<!-- WURST_AGENTS_TEMPLATE_VERSION: 2026-08-29 -->
22
# AGENTS.md - WurstScript Map Project Notes
33

44
WurstScript Warcraft III map project notes for editing `.wurst` code, dependencies, generated objects, tests, or map build logic.
@@ -42,7 +42,19 @@ Read `scriptMode` before adding or removing `execute()` or timer chunking. Do no
4242

4343
## High-Risk Wurst Semantics
4444

45-
- Closures capture locals by value. Assigning inside a callback does not update the captured outer local. Keep creation and follow-up handlers in the same closure, store shared mutable state on an owning class, or use `reference(value)` and destroy it when finished.
45+
- Prefer null-safe access (`?.`) when a missing receiver means no-op: the receiver is evaluated once and call arguments only when non-null. Keep an explicit check for null handling, primitive-valued results, or assignments. Example: `findTarget()?.damage(50.)`.
46+
- Closures capture locals by value; callback assignments do not update the outer local. Inside a closure, `it` is that closure object, so use it for self-cancellation or cleanup instead of a temporary or `reference` used only to reach it:
47+
48+
```wurst
49+
doPeriodically(0.25) ->
50+
if isFinished()
51+
destroy it
52+
return
53+
```
54+
55+
`it` is not shared state; use an owning class or `reference(value)` for shared mutation, and destroy the reference when finished.
56+
- Use `public readonly` for API fields callers may read but only the declaring class, module, or package may update, e.g. `public readonly int charges`. Unlike `constant`/`let`, the owner may update it repeatedly; visibility and write access are independent (`private readonly` hides reads).
57+
4658
- Wurst class lifetime remains explicit for Lua output. Objects created with `new`, stored closures/listeners, references, and owned collections usually need `destroy`; owners should clear stale references after destruction and must avoid double-destroy.
4759
- WC3 `int` is signed 32-bit and overflows silently. Promote before multiplication (`worth.toReal() * count`), never after an integer expression has already overflowed.
4860
- Lambdas require a known target type. Lambdas used as `code` cannot accept parameters or capture locals.

0 commit comments

Comments
 (0)