// my1stmod.js - Configurable delay gate for Sandboxels elements.delay_gate = { color: "#8B4513", behavior: behaviors.wall, category: "machines", state: "solid", conduct: 1, properties: { delay: 30, timer: 0, powered: false }, tick: function(pixel) { // Initialize properties if (pixel.delay === undefined) pixel.delay = 30; if (pixel.timer === undefined) pixel.timer = 0; if (pixel.powered === undefined) pixel.powered = false; // Check power from below (input) let below = getPixel(pixel.x, pixel.y + 1); let receivingPower = below && (below.charge || below.chargeCD); // Check side inputs for delay adjustment let left = getPixel(pixel.x - 1, pixel.y); let right = getPixel(pixel.x + 1, pixel.y); // Left side = decrease delay (minimum 5) if (left && (left.charge || left.chargeCD) && pixel.delay > 5) { pixel.delay--; pixel.color = "#A0522D"; } // Right side = increase delay (maximum 300) else if (right && (right.charge || right.chargeCD) && pixel.delay < 300) { pixel.delay++; pixel.color = "#654321"; } else if (!receivingPower || pixel.timer >= pixel.delay) { pixel.color = "#8B4513"; } // Main delay logic if (receivingPower) { if (!pixel.powered) { pixel.powered = true; pixel.timer = 0; } pixel.timer++; // Visual progress indication if (pixel.timer < pixel.delay) { let progress = pixel.timer / pixel.delay; let r = Math.floor(139 + (100 * progress)); pixel.color = "rgb(" + r + ", 69, 19)"; } // Output when delay reached if (pixel.timer >= pixel.delay) { let above = getPixel(pixel.x, pixel.y - 1); if (above && elements[above.element].conduct) { above.charge = 1; above.chargeCD = 5; } pixel.color = "#FFD700"; } } else { pixel.powered = false; pixel.timer = 0; } } };