View Single Post
  #1  
Old 06-12-2012, 03:17 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Issues with .link()

Hey guys,

I'm trying to use .link() in a script i'm working on. I would assume it would work like this,

PHP Code:
function onCreated() {
  
this.number 5;
  
temp.clone = this.number;
  
temp.clone = 10;
  
printf("this.number = %i"this.number); //Outputs 5
  
printf("temp.clone = %i"temp.clone); //Outputs 10
  
echo("--------");
  
temp.link this.number.link();
  
printf("temp.link = %i"temp.link); //Outputs 5
  
temp.link 20;
  
printf("this.number = %i"this.number); //Outputs 5 -- Expected 20?
  
printf("temp.clone = %i"temp.clone);  //Ouputs 10
  
printf("temp.link = %i"temp.link);  //Outputs 20

I also tried a different example,
PHP Code:
function onCreated() {
  
this.num1 1;
  
this.num2 2;
  
this.array = {this.num1.link(), this.num2.link()};
  
printf("Pre-Change: %s"this.array);
  
  for (
i=0i<2i++)
    
this.array[i] = 20;
  
  
printf("Post-Change: %s"this.array);
  
  echo(
"this.num1 = " this.num1);
  echo(
"this.num2 = " this.num2);
}

Pre-Change1,2
Post
-Change20,20
this
.num1 1
this
.num2 
This was tested on Testbed.

I would have thought temp.link = this.number.link(); would make temp.link reference this.number rather than copying the object but the output shows opposite.

Is .link() supposed to be returning a reference or is it providing another use?
Reply With Quote