|
1 | | -<!-- WURST_AGENTS_TEMPLATE_VERSION: 2026-08-08 --> |
| 1 | +<!-- WURST_AGENTS_TEMPLATE_VERSION: 2026-08-29 --> |
2 | 2 | # AGENTS.md - WurstScript Map Project Notes |
3 | 3 |
|
4 | 4 | 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 |
42 | 42 |
|
43 | 43 | ## High-Risk Wurst Semantics |
44 | 44 |
|
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 | + |
46 | 58 | - 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. |
47 | 59 | - WC3 `int` is signed 32-bit and overflows silently. Promote before multiplication (`worth.toReal() * count`), never after an integer expression has already overflowed. |
48 | 60 | - Lambdas require a known target type. Lambdas used as `code` cannot accept parameters or capture locals. |
|
0 commit comments