CodingTrain / CodingTrain/Suggestion-Box

Question regarding Object Communication video 7.7

Offen
#754 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Question
Vorherrschende Sprache
Keine Sprachdaten
Sterne
570
Forks
85
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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!

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Die Nutzlast verweist auf das Video 7.7 zu Object Communication und den dort gezeigten finalen Code; beginne mit der Überprüfung dieses Beispiels und der Scope-Regeln der Frage. Erledigt bedeutet, eine dokumentierte Erklärung bereitzustellen, die den Zugriff auf beide Objekte behandelt, ohne das Interaktionsproblem mit nur dem letzten Objekt wieder einzuführen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
content
Issue-Typ
Dokumentation
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.