Send a radio message to the parent carrier
Separate sending, filtering and receiving into small responsibilities
Establish a clear parent relationship
The radio is a separate unit placed on the carrier through attachment_radio, it can address its carrier using parent, that reference depends on the real attachment relationship
[attachment_radio]
x: 0
y: -3
onCreateSpawnUnitOf: rwa07Radio
showAllActionsFrom: true
isUnselectable: true
canBeAttackedAndDamaged: falseSend only the data needed for this event
The radio button does not directly edit carrier memory, it sends a v07signal message containing pulse, the tag describes the purpose and the data describes this event
[action_sendSignal]
text: 发出联络信号 / Send a signal
buildSpeed: 0
sendMessageTo: parent
sendMessageWithTags: v07signal
sendMessageWithData: pulse=1Let the receiver decide the response
The receiving action listens for its own tag and adds the event pulse to its counter, eventData belongs to this event while memory keeps a persistent record, a default of zero avoids incrementing on a missing value
[hiddenAction_receiveSignal]
autoTriggerOnEvent: newMessage(withTag='v07signal')
setUnitMemory: signals=memory.signals + eventData(name='pulse',type='number',default=0)
showMessageToPlayer: Signal count: %{memory.signals}Avoid message feedback loops
Start with a one-way chain, one radio send should produce one carrier update, if acknowledgments are added later, use a different tag and stop the chain at its receiver instead of forwarding the same message back and forth
Try it yourself
Change pulse to 2 and send three messages, predict the count before observing it