Object linking

Monkey Forums/Monkey Programming/Object linking

Raz(Posted 2012) [#1]
Hi everyone, am I right in thinking that in the following, thisItem is actually a link (node?) to an instance of that item, instead of the actual instance itself?

' Lets say this has 20 objects, 0 - 19
Global allItems:SomeItem[] 

Class SomeItem

' For this example lets say its "bob" followed by the number, so bob0, bob1, bob2, bob3... bob19
Field name:String 

Field thisItem:SomeItem

Method setThisItem:Void(newItem:SomeItem)
thisItem = newItem
End Method

End Class

So... if I were to run
allItems[5].setThisItem(allItems[6])

and then run
allItems[6].name = "Woop"

running
print allItems[5].thisItem.name

would give me "Woop"?

So allItems[5].thisItem and allItems[6] are actually still the same object?

Edit, I ask because I am not somewhere where I can run Monkey ;)


Jesse(Posted 2012) [#2]
when you assign an object to a variable all you are doing is assigning the object's address to the variable. In that case your last two code example and your conclusion are correct.


Jesse(Posted 2012) [#3]
double post.


Raz(Posted 2012) [#4]
Cheers Jesse :D