############################# in Cadence ################################################################################################################# ## note: after entering all the code, reset the time to initalize the chessclock (see "scripts for testing") ##### @root chessclock=(new); @root chessclock reset=false start_time=(30*60) active=A A = (new time := { if (..reset) { ...start_time } else if (...active == A) { ## don't forget the space, ...active==A gives a syntax error!!! ## ..time - (@root itime) } else { ..time } } button = false ) B = (new time := { if (..reset) { ...start_time } else if (...active == B) { ..time - (@root itime) } else { ..time } } button =true ) active:= { if (.active == A and (.A button)) {B} else if (..active == B and (..B button)) {A} else {..active } } ######################################################## scripts for testing ########################################################### ## step1: reset the chessclock!!! .chessclock reset=true; .chessclock reset=false; ## step2: switch A and B .chessclock B button=false; .chessclock A button=true; ## active now is B .chessclock A button=false; .chessclock B button=true; ## active now is A .chessclock A button=true; .chessclock B button=true; ## active switching between A and B