Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda