You can't get A outside that function. Once the scope closes, it's gone.
Instead, you can use a script like this to do it:
(function foreverLoop() {
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
const { width, height } = canvas;
const imgData = ctx.getImageData(0, 0, width, height);
const data = imgData.data;
const visited = new Uint8Array(width * height);
// === Colors & Thresholds ===
const ballColor = [230, 230, 230];
const ballThreshold = 40;
const barColor = [230, 230, 230];
const barThreshold = 40;
function colorMatch(r, g, b, target, threshold) {
return (
Math.abs(r - target[0]) < threshold &&
Math.abs(g - target[1]) < threshold &&
Math.abs(b - target[2]) < threshold
);
}
function getPixelIndex(x, y) {
return (y * width + x) * 4;
}
function getVisitedIndex(x, y) {
return y * width + x;
}
function floodFill(x, y, targetColor, threshold) {
const queue = [[x, y]];
const pixels = [];
let minX = x, maxX = x, minY = y, maxY = y;
while (queue.length) {
const [cx, cy] = queue.pop();
const idx = getVisitedIndex(cx, cy);
if (visited[idx]) continue;
visited[idx] = 1;
const pixIdx = getPixelIndex(cx, cy);
const [r, g, b] = data.slice(pixIdx, pixIdx + 3);
if (!colorMatch(r, g, b, targetColor, threshold)) continue;
pixels.push([cx, cy]);
minX = Math.min(minX, cx);
maxX = Math.max(maxX, cx);
minY = Math.min(minY, cy);
maxY = Math.max(maxY, cy);
for (let dx = -1; dx <= 1; dx++) {
for (let dy = -1; dy <= 1; dy++) {
const nx = cx + dx;
const ny = cy + dy;
if (
nx >= 0 && nx < width &&
ny >= 0 && ny < height &&
!visited[getVisitedIndex(nx, ny)]
) {
queue.push([nx, ny]);
}
}
}
}
return { pixels, minX, maxX, minY, maxY };
}
const balls = [];
const bars = [];
// === Scan image for BALLS ===
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
if (visited[getVisitedIndex(x, y)]) continue;
const idx = getPixelIndex(x, y);
const [r, g, b] = data.slice(idx, idx + 3);
if (colorMatch(r, g, b, ballColor, ballThreshold)) {
const region = floodFill(x, y, ballColor, ballThreshold);
const size = region.pixels.length;
if (size >= 400 && size <= 500) {
const sum = region.pixels.reduce((acc, [px, py]) => [acc[0] + px, acc[1] + py], [0, 0]);
const cx = sum[0] / size;
const cy = sum[1] / size;
balls.push({ x: cx, y: cy, size });
}
}
}
}
// === Reset visited array ===
visited.fill(0);
// === Scan image for BARS ===
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
if (visited[getVisitedIndex(x, y)]) continue;
const idx = getPixelIndex(x, y);
const [r, g, b] = data.slice(idx, idx + 3);
if (colorMatch(r, g, b, barColor, barThreshold)) {
const region = floodFill(x, y, barColor, barThreshold);
const { pixels, minX, maxX, minY, maxY } = region;
const widthBox = maxX - minX + 1;
const heightBox = maxY - minY + 1;
const area = widthBox * heightBox;
const aspectRatio = widthBox / heightBox;
if (widthBox > 100 && aspectRatio > 4) {
const cx = (minX + maxX) / 2;
const cy = (minY + maxY) / 2;
bars.push({ x: cx, y: cy, width: widthBox, height: heightBox });
}
}
}
}
if (balls.length === 0 || bars.length === 0) {
console.warn("Could not find bar or ball. Retrying...");
setTimeout(foreverLoop, 500);
return;
}
// === Get targets ===
const ball = balls[balls.length - 1];
const bar = bars[0];
const direction = bar.x < ball.x ? 'ArrowRight' : 'ArrowLeft';
const keyCode = direction === 'ArrowRight' ? 39 : 37;
const moveStep = 3;
const maxSteps = 200;
function simulateKeyDown(key, keyCode) {
const event = new KeyboardEvent("keydown", {
key, code: key, keyCode, which: keyCode, bubbles: true,
});
document.dispatchEvent(event);
}
function simulateKeyUp(key, keyCode) {
const event = new KeyboardEvent("keyup", {
key, code: key, keyCode, which: keyCode, bubbles: true,
});
document.dispatchEvent(event);
}
let currentX = bar.x;
let steps = 0;
console.log("currentx: " + currentX)
console.log("ballx: " + ball.x)
const moveInterval = setInterval(() => {
const delta = Math.abs(currentX - ball.x);
if (delta <= moveStep || steps >= maxSteps) {
simulateKeyUp(direction, keyCode);
clearInterval(moveInterval);
setTimeout(foreverLoop, 100); // 🔁 Loop again
return;
}
simulateKeyDown(direction, keyCode);
currentX += direction === 'ArrowRight' ? moveStep : -moveStep;
steps++;
}, 16);
})();
This is a little glitchy, but it gets ~500 points without fail. Paste it in the console after you open the game but before you start playing, then start the game and let the script do it's job. It does not avoid poison and only works with white balls