ID:140059
 
Code:Hiead Link Object Demo
atom
icon = 'icon.dmi'

movable
animate_movement = 0

var/atom/movable/ChildObject = null


proc/Add_Link()
var/atom/movable/testLink = src //creates a new object and adds it to players location
while(testLink.ChildObject) //while testLink's var "ChildObject" is not 0
testLink = testLink.ChildObject // testLink becomes its own ChildObject

var/obj/Link/newLink = new(testLink.loc) //Creates a new obj "newLink" places it ontop of "testLink"
testLink.ChildObject = newLink //Re-assigns the [testlink.as.its.own.child] so that newLink becomes Testlink's Childobject

Move()
var/last_loc = loc //saving in a var the location of newLink..????

. = ..() //I don't understand the purpose of this at all


if(ChildObject && .) //if childobj AND whatever "." is have values??
ChildObject.Move(last_loc) //move ChildObject to testLink's childobject's last location??



client/verb/Additional_Link()
mob.Add_Link()

Problem description: I'm trying to understand this code. I've filled in the comments to illustrate how I see it please if someone could break this down for me?

        proc/Add_Link()
var/atom/movable/testLink = src //creates a new object and adds it to players location
while(testLink.ChildObject) //while testLink's var "ChildObject" is not 0
testLink = testLink.ChildObject // testLink becomes its own ChildObject


This is simply finding the last object in the chain of objects. No new objects are being created and nothing is being modified. It's just following the chain of ChildObject pointers.

            var/obj/Link/newLink = new(testLink.loc)    //Creates a new obj "newLink" places it ontop of "testLink"
testLink.ChildObject = newLink //Re-assigns the [testlink.as.its.own.child] so that newLink becomes Testlink's Childobject


You basically have it right, once you understand that "testLink" is really the last link in the chain. So, it's creating a new object and setting the tail's child to be the new link. Really, the "testLink" variable should be renamed "tail" for clarity.

        Move()  
var/last_loc = loc //saving in a var the location of newLink..????


newLink is not involved here at all. This is simply saving the current location, because the object will move momentarily.

            . = ..() //I don't understand the purpose of this at all


This performs the default action (..()) and stores it in the variable . which is the default return value (so, the last line of any proc is implied to be "return ."). This is basically "do what you would've done".

            if(ChildObject && .)    //if childobj AND whatever "." is have values??
ChildObject.Move(last_loc) //move ChildObject to testLink's childobject's last location??


And this just means "if we have a child, and we moved successfully, then move the child to where we just were". There's an additional bit you have to get, though: the child's Move() proc is going to do the same thing, moving its child into its old location, and so on until the end of the chain. So, the entire thing moves all at once.