Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
No se puede actualizar la propiedad del objeto cuando se ejecuta setInterval

Estaba tratando de cambiar la propiedad de los objetos dentro this._keys . El método que estoy usando funcionó bien para cambiar la propiedad, pero el problema es que tengo una instrucción if que decide si la propiedad cambia o no y que la instrucción if verifica si una variable es igual a una cadena. Esa variable es dinámica, por lo que debo setInterval para seguir actualizando los datos. Pero cuando configuro Interval, ya no puedo actualizar la propiedad del objeto. Recibo el error Cannot set properties of undefined (setting 'forward') . ¿Por qué no puedo cambiar la propiedad mientras actualizo los datos? He comentado en mi código para señalar mejor el problema. Se agradece cualquier ayuda sobre por qué ocurre esto y cómo solucionarlo. Gracias por adelantado.

 const currentKeylogW, currentKeylogA, currentKeylogD, currentKeylogS = a dynamic data; class BasicCharacterControllerInput2 { constructor() { this._Init(); } _Init() { this._keys = { forward: false, backward: false, left: false, right: false, space: false, shift: false, shiftForward: false, }; //this has no error but currentKeylog's variables are not being updtes so its useless if (currentKeylogW == '"w"') { this._keys.forward = true; } else if (currentKeylogA == '"a"') { this._keys.left = true; } else if (currentKeylogD == '"d"') { this._keys.left = true; } else if (currentKeylogS == '"s"') { this._keys.right = true; } else if (currentKeylogW == '"!w"') { this._keys.forward = false; } else if (currentKeylogA == '"!a"') { this._keys.left = false; } else if (currentKeylogD == '"!d"') { this._keys.left = false; } else if (currentKeylogS == '"!s"') { this._keys.right = false; } //updates currentKeylog's variables but can't set forward,.. properties setInterval(function() { if (currentKeylogW == '"w"') { this._keys.forward = true; } else if (currentKeylogA == '"a"') { this._keys.left = true; } else if (currentKeylogD == '"d"') { this._keys.left = true; } else if (currentKeylogS == '"s"') { this._keys.right = true; } else if (currentKeylogW == '"!w"') { this._keys.forward = false; } else if (currentKeylogA == '"!a"') { this._keys.left = false; } else if (currentKeylogD == '"!d"') { this._keys.left = false; } else if (currentKeylogS == '"!s"') { this._keys.right = false; } }, 500) } }

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!