Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
I can't access my javascript code because of infinite prompts

Help, I've been using this website called "codepen" to do some javascript coding. But I accidently made it send me infinite prompts, everytime I open the project. Now I can't access the code. I searched for some time for an answer but I found none. heres a link to the problem: https://codepen.io/Aibel-Roy/pen/zYPBeEW

//I can't post the code because of the infinite prompts. Sorry.
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Here's your code:

//config
var tick = 50;
var fieldOfView = 25;
var Speed = 0.25;
var ZMulti = 4;
var ClearOnDraw = true;

// variables
var keymap = [];
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var meshA = [
  "0,0,0",
  "1,0,0",
  "1,1,0",
  "0,1,0",
  "0,0,1",
  "1,0,1",
  "0,1,1",
  "1,1,1"
];
var textures = [
  "http://www.textures4photoshop.com/tex/thumbs/red-sofa-leather-seamless-texture-53.jpg"
];
var cameraData = [0, 0, 0];

//keymap
window.addEventListener(
  "keydown",
  (event) => {
    var name = event.key;
    keymap.push(name);
  },
  false
);
window.addEventListener(
  "keyup",
  (event) => {
    var name = event.key;
    if (keymap.includes(name)) {
      keymap.splice(keymap.indexOf(name), 1);
    }
  },
  false
);

//render img
function draw() {
  if (ClearOnDraw) {
    ctx.clearRect(0, 0, 10000, 1000);
  }
  var img = new Image(); // texturing
  img.src = textures[0];
  prompt(img.src);
  img.onLoad = function () {
    var pattern = context.createPattern(imageObj, "repeat");
    ctx.fillStyle = pattern;
    var prevVert;
    for (let i = 0; i <= meshA.length; i++) {
      //convert 3D vector to 2D
      var vert = meshA[i];
      if (i >= meshA.length) {
        vert = meshA[0];
      }
      var vertPos = vert.split(",");
      var zMag = (vertPos[2] - cameraData[2]) * (fieldOfView / ZMulti);
      var vertPos2D = [
        (vertPos[0] - cameraData[0]) * fieldOfView + zMag,
        (vertPos[1] - cameraData[1]) * fieldOfView + zMag
      ];

      ctx.beginPath();
      ctx.moveTo(vertPos2D[0], vertPos2D[1]);
      for (let i1 = 0; i1 < meshA.length; i1++) {
        var prv = meshA[i1].split(",");
        var PrevzMag = (prv[2] - cameraData[2]) * (fieldOfView / ZMulti);
        var I1VertPos = [
          (prv[0] - cameraData[0]) * fieldOfView + PrevzMag,
          (prv[1] - cameraData[1]) * fieldOfView + PrevzMag
        ];
        ctx.lineTo(I1VertPos[0], I1VertPos[1]);
        ctx.stroke();
      }
      ctx.closePath();
      ctx.fill();
      prevVert = vertPos2D;
    }
  };
}
function Movement() {
  if (keymap.includes("w")) {
    cameraData[2] -= Speed * 2;
  }
  if (keymap.includes("s")) {
    cameraData[2] += Speed * 2;
  }
  if (keymap.includes("d")) {
    cameraData[0] -= Speed;
  }
  if (keymap.includes("a")) {
    cameraData[0] += Speed;
  }
}

draw();
setInterval(function main() {
  draw();
  Movement();
}, tick);

How to disable the prompt(if the browser doesn't suggest you to suppress it):

  1. On that page, bring up dev tools(Command + Option + I, or F12 on Windows).

  2. Choose the correct page on the dev tool, usually looks like CodePen (Hash ID)

  3. Override the prompt function in the console by typing window.prompt = () => {}.

  4. Change your code, save and refresh the page.

There are probably better ways to do it but disabling JavaScript makes the code section unusable.

about 4 years ago · Juan Pablo Isaza Denunciar

0

In your function draw(), there is a prompt in here:

function draw() {
  // Trimmed
  prompt(img.src);
  
  // Trimmed
}

You also have setInterval calling draw() at a particular interval defined in tick (where you have assigned 50ms as the value):

setInterval(function main() {
  draw();
  Movement();
}, tick);

As a result, draw() gets called every 50ms, where prompt(img.src) gets called, leading to infinite prompt.

You need to change whatever you are doing in setInterval().

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda