I need node.ConnectedTo explained to me

so as far as i can tell in the node object we have a variable called connectedTo of type Node,
and we are using it to track are path from the destination point back to the starting point, but I dont know why it works for what we are using it for, as far as i can tell its just a variable that doesnt do anything when i look at the Node script.

I don’t understand the question, really. You say what the variable is used for and then ask what the variable is used for. It is used to track a path.

It does do something; it tells us which node this one is connected to in the path - if any

Hi Adrian,

Welcome to our community! :slight_smile:

Let’s say we named our nodes A, B, C, D, E. A is our starting node, and D is our target node. As bixarrio wrote, the connectedTo variable of one node object references another node object (or nothing, which is null).

This is what we call a path: A -> C -> B -> E -> D -> null.

You are right, the variable itself does not do anything. Variables never do anything. They have a value assigned, and that’s it. We are usually able to read and override the value.

In our code, we would get to A from D with: A.connectedTo.connectedTo.connectedTo.connectedTo.

If you find this hard to grasp, imagine you would want to invite all your friends to your party but you do not know their phone numbers. However, you know the number of one friend who you call. And that friend calls the next friend who calls the next friend who calls the next friend, and so on, until all friends were called.

Something very similar happens in the code.

Did this clear it up for you? :slight_smile:


See also:

1 Like

It does thanks for the reply.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms