Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Issues with .link() (https://forums.graalonline.com/forums/showthread.php?t=134266631)

Twinny 06-12-2012 03:17 PM

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?

Twinny 06-12-2012 03:54 PM

As per Stefan,

Quote:

Assignments are always resolving links, the link() function is more
for passing complex variables to functions
He suggested TStaticVars which could get around my array issue like this,

PHP Code:

function onCreated() {
  
temp.obj1 = new TStaticVar();
  
temp.obj1.num 1;
  
  
temp.obj2 = new TStaticVar();
  
temp.obj2.num 2;
  
  
temp.array = {temp.obj1temp.obj2};
  
temp.array[0].num 5;
  echo(
temp.array[0].num); //Outputs 5
  
echo(temp.obj1.num); //Outputs 5

  
temp.obj1.destroy();
  
temp.obj2.destroy();


It works but is definitely not what I had desired.


All times are GMT +2. The time now is 03:56 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.