CodingTrain / CodingTrain/Suggestion-Box

Question regarding Object Communication video 7.7

Abierto
#754 4 comentarios 0 reacciones 0 asignados Ver en GitHub
Question
Lenguaje dominante
Sin datos de lenguaje
Estrellas
570
Forks
85
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hello! I have a question in regards to the final result of the object communication code found in your program at the end of the 7.7 video. The code reads like this:

`for (b of bubbles) {`
` b.show();`
` b.move();`
` let overlapping = false;`
` for (other of bubbles) {`
` if (b !== other && b.intersects(other)) {`
` overlapping = true;`
` }`
` }`
` if (overlapping) {`
` b.changeColor(255);`
` } else {`
` b.changeColor(0);`
` }`
`}`

Please forgive me if I cannot ask this question properly: How would you, in this example, reference the *other* object within the *b* object's code? For example...

Let's say I want to draw a line that is 500 pixels long from the x and y of the *b* object at a random angle outwards every frame. Now, if an *other* object is "within range", so within 500 pixels of the *b* object, then draw the line from the x and y of the *b* object to the x and y of the *other* object (now less than 500 pixels long).

In the case above, I would need to pull the x and y coordinates of the *b* object and the *other* object within the same scope. The problem that I am having is that the if statement regarding overlapping being true or false is removed from the scope of the `for (other of bubbles)` loop, and as explained in the video, is necessary to avoid the problem of only-last-object interaction. So how could you remove the *other* object from scope while also running through the for loop every frame, while simultaneously avoiding the only-last-interaction problem?

Thank you!

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

La carga útil apunta al vídeo 7.7 de Object Communication y al código final mostrado allí; empieza revisando ese ejemplo y las reglas de ámbito de la pregunta. Se considera terminado cuando se proporciona una explicación documentada que aborda el acceso a ambos objetos sin reintroducir el problema de interacción que solo afecta al último objeto.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
content
Tipo de issue
Documentación
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.