/** SSDemo2s share the highest Score among their connected group. */ element SSDemo2 { // Typedefs typedef Unsigned(8) Score; // Utilities EventWindow ew; Random random; DebugUtils du; // Data members Score val; Void behave() { if (val == 0) // randomize initial vals val = random.bits(val.sizeof); WindowServices ws; // Scanning support SelectorServices ss; // Selection support ws.reset(0,4); // Scan everyone including us ss.reset(); for (Int idx = ws.next(); idx >= 0; idx = ws.next()) { Atom a = ew[idx]; if (a as SSDemo2) ss.maximize((Int) a.val); // Don't need the idx this way.. } // We scanned ourselves, so we know ss.selectionMade() will be // true. So we just take the chosen value (even if it was ours). val = (Score) ss.getSelectedValue(); du.printContext(); } }