CodingTrain / CodingTrain/Suggestion-Box

Question regarding Object Communication video 7.7

Ouverte
#754 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Question
Langage dominant
Aucune donnée de langage
Étoiles
570
Forks
85
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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!

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

La charge utile renvoie à la vidéo 7.7 sur Object Communication et au code final qui y est présenté ; commencez par examiner cet exemple ainsi que les règles de portée de la question. Le travail est terminé lorsqu’une explication documentée traite de l’accès aux deux objets sans réintroduire le problème d’interaction avec le dernier objet uniquement.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript
Domaine
content
Type d'issue
Documentation
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
25/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.