Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 06-12-2012, 03:54 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
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:18 PM.


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