You are basically creating a linked list. Each segment points to a parent link (head) and a child link (tail). When you create the snake, you create the first segment with n = nme6.Create(). Then the next segment is created and n.tail is set to point to it.
n.tail = nme6.Create()
now n.tail points to the second segment, but you need to point the second segment's head back to the first segment.
n.tail.head = n
Let me break that down.
n is the instance of the first segment
n.tail is the instance of the second segment
n.tail.head is the head field of the second segment which now needs to point to the first segment.
So now the two segments look like this
Segment1
Tail: Points to Segment1
Head:Points to Null (not yet defined)
Segment2
Tail:Points to Null(not yet defined)
Head:Points to Segment 1
After adding the third segment, it will look like this
Segment1
Tail: Points to Segment2
Head: Points to Null
Segment2
Tail Points to Segment3
Head Points to Segment1
Segment3
Tail: Points to Null
Head: Points to segment2
n.tail = nme6.Create()
now n.tail points to the second segment, but you need to point the second segment's head back to the first segment.
n.tail.head = n
Let me break that down.
n is the instance of the first segment
n.tail is the instance of the second segment
n.tail.head is the head field of the second segment which now needs to point to the first segment.
So now the two segments look like this
Segment1
Tail: Points to Segment1
Head:Points to Null (not yet defined)
Segment2
Tail:Points to Null(not yet defined)
Head:Points to Segment 1
After adding the third segment, it will look like this
Segment1
Tail: Points to Segment2
Head: Points to Null
Segment2
Tail Points to Segment3
Head Points to Segment1
Segment3
Tail: Points to Null
Head: Points to segment2