# detach.ludic — the structural attach/detach pair and its @OnAttach / @OnDetach # hooks. `attach P on e` adds a property to a LIVE entity (seeding its fields and # firing @OnAttach); `detach P on e` removes it (firing @OnDetach, which still # reads the outgoing value before the has-flag clears). This is the structural # counterpart to enable/disable — attach/detach create and destroy the property's # presence, whereas disable/enable only pause it while keeping the data. # # Running it prints: 15 1 25 0 # 15 @OnAttach(Shield): amount seeded to 5, prints 5 + 10 # 1 one live Shield now matches the query # 25 @OnDetach(Shield): reads the outgoing amount 5, prints 5 + 20 # 0 the Shield is gone — nothing matches # # bin/ludic-dev game-build bin/ludicc examples/lang/detach.ludic /tmp/detach # /tmp/detach 15 var n = 0 for (s) in query [Shield] { n += 1 } print(n) # 1 for (s) in query [Shield] { detach Shield on self() } # @OnDetach -> 25 n = 0 for (s) in query [Shield] { n += 1 } print(n) # 0 quit() } }