DEV Community

Chinmay Danodiya
Chinmay Danodiya

Posted on

I need help

Can anyone help me to fix this code as it will work, I made a whole computer in app script only of google sheets and a menur should appear, can anyone help me to fix it?
Hear is the code:-
/**

  • 12-THREAD MONOLITHIC SOC: FIXED MASTER BUILDER */

const ADDR = {
OS_BIN: "https://raw.githubusercontent.com/copy/v86/master/bios/seabios.bin",
DISPLAY: "F2:O11",
UP: "C15",
LEFT: "B16",
SELECT: "C16",
RIGHT: "D16",
DOWN: "C17",
REG_X: "C2",
REG_Y: "D2"
};

/**

  • ADDS THE MENU TO THE TOOLBAR */ function onOpen() { const ui = SpreadsheetApp.getUi(); ui.createMenu('๐Ÿ•น๏ธ SoC Master') .addItem('๐Ÿš€ Boot OS', 'bootSequence') .addSeparator() .addItem('๐Ÿงน Wipe System', 'wipeSystem') .addToUi(); }

/**

  • THE BOOT SEQUENCE */ function bootSequence() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getActiveSheet();

sheet.clear();
sheet.getRange("A:Z").setBackground(null);

// Format Screen
const display = sheet.getRange(ADDR.DISPLAY);
display.setBackground("black");
for (let i = 6; i <= 15; i++) {
sheet.setColumnWidth(i, 45);
sheet.setRowHeight(i - 4, 45);
}

// Draw Buttons
const btn = (cell, label, color) => {
sheet.getRange(cell).setValue(label).setBackground(color).setFontColor("white")
.setHorizontalAlignment("center").setVerticalAlignment("middle").setFontWeight("bold");
};

btn(ADDR.UP, "โ–ฒ", "#2c3e50");
btn(ADDR.LEFT, "โ—€", "#2c3e50");
btn(ADDR.SELECT, "EXE", "#c0392b");
btn(ADDR.RIGHT, "โ–ถ", "#2c3e50");
btn(ADDR.DOWN, "โ–ผ", "#2c3e50");

// Init Registers
sheet.getRange("C1:D1").setValues([["REG_X", "REG_Y"]]).setFontWeight("bold");
sheet.getRange(ADDR.REG_X).setValue(5);
sheet.getRange(ADDR.REG_Y).setValue(5);

// Flash Binary
try {
const res = UrlFetchApp.fetch(ADDR.OS_BIN);
const data = res.getContent();
const ram = [];
for (let i = 0; i < 50; i++) ram.push([data[i]]);
sheet.getRange("A1:A50").setValues(ram);
} catch (e) {
sheet.getRange("A1").setValue("BOOT_ERR");
}

render(sheet, 5, 5, "#00FF00");
}

/**

  • INTERRUPT HANDLER */ function onSelectionChange(e) { const a1 = e.range.getA1Notation(); const sheet = e.range.getSheet();

let x = sheet.getRange(ADDR.REG_X).getValue();
let y = sheet.getRange(ADDR.REG_Y).getValue();
if (x === "" || y === "") return;

render(sheet, x, y, "black");

if (a1 === ADDR.UP) y = Math.max(1, y - 1);
if (a1 === ADDR.DOWN) y = Math.min(10, y + 1);
if (a1 === ADDR.LEFT) x = Math.max(1, x - 1);
if (a1 === ADDR.RIGHT) x = Math.min(10, x + 1);
if (a1 === ADDR.SELECT) {
const screen = sheet.getRange(ADDR.DISPLAY);
screen.setBackground("#00ff00");
SpreadsheetApp.flush();
Utilities.sleep(150);
screen.setBackground("black");
}

sheet.getRange(ADDR.REG_X).setValue(x);
sheet.getRange(ADDR.REG_Y).setValue(y);
render(sheet, x, y, "#00FF00");
}

function render(sheet, x, y, color) {
sheet.getRange(y + 1, x + 5).setBackground(color);
}

function wipeSystem() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.clear().getRange("A:Z").setBackground(null);
}

Top comments (0)