// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Run a bounded work and break cycle // Not compiled or tested in-world // Setup: Edit WORK, REST, and ROUNDS. Touch to start or cancel. // Stop / restore: Remove, disable, or reset to stop timers and discard session state. Temporary input listeners expire after 45 seconds. // Notes: Only the current owner can control this example. Timing is approximate and can be delayed by simulator load. Only phase-change messages are emitted. A delayed timer starts the next phase when processed; it does not burst through missed notifications. // License: see LICENSE in this distribution. // Original Incoprea example. MIT. integer active; integer handle; integer channel; integer expires; integer WORK=300; integer REST=60; integer ROUNDS=3; integer round; integer phase; integer due; closeInput() { if(handle)llListenRemove(handle); handle=0; } schedule() { if(active || handle)llSetTimerEvent(1.0); else llSetTimerEvent(0.0); } default { touch_start(integer touches) { if(llDetectedKey(0)!=llGetOwner())return; if(active) { active=FALSE; llOwnerSay("Cycle cancelled."); } else if(WORK<5 || REST<5 || WORK>3600 || REST>3600 || ROUNDS<1 || ROUNDS>12)llOwnerSay("Invalid cycle limits."); else { round=1; phase=0; active=TRUE; due=llGetUnixTime()+WORK; llOwnerSay("Work round 1 begins."); } schedule(); } listen(integer c,string name,key speaker,string input) { if(c!=channel || speaker!=llGetOwner() || !handle)return; closeInput(); if(llStringLength(input)>200) { llOwnerSay("Reply is too long."); schedule(); return; } schedule(); } timer() { if(handle && llGetUnixTime()>=expires) { closeInput(); llOwnerSay("Input expired."); } if(active && llGetUnixTime()>=due) { if(phase==0) { phase=1; due=llGetUnixTime()+REST; llOwnerSay("Break begins."); } else if(round>=ROUNDS) { active=FALSE; llOwnerSay("All work/break rounds complete."); } else { ++round; phase=0; due=llGetUnixTime()+WORK; llOwnerSay("Work round "+(string)round+" begins."); } } schedule(); } changed(integer flags) { if(flags & CHANGED_OWNER)llResetScript(); } }