Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Script Questions (Globals, Types, References, .link(), TStaticVar) (https://forums.graalonline.com/forums/showthread.php?t=134269553)

Inari 09-13-2014 10:26 AM

Script Questions (Globals, Types, References, .link(), TStaticVar)
 
(I tried my best in making this follow-able and readable, but I tend to be bad at explaining, so please ask if something is unclear)

Globals

When are global variables reset? Do they last till the server is restarted? Are they affected by some kind of Garbage Collection?

Types

Every uninitialized variable appears to be a TGraalVar according to .objecttype(), why is that?

References

What is passed by reference and what is passed by value? What can store a reference? How does .link() affect that?

To elaborate:
PHP Code:

function onCreated()
{
  
test"x" );
  
temp.this.list.x;
  
temp.5;
  
send"temp.p / objecttype: " temp.p.objecttype() @ " / type: " temp.p.type() @ " / tostring: " temp." / is null: " @ ( temp.== null ) );
  
send"temp.x / objecttype: " temp.x.objecttype() @ " / type: " temp.x.type() @ " / tostring: " temp." / is null: " @ ( temp.== null ) );
  
send"temp.x.text / objecttype: " temp.x.text.objecttype() @ " / type: " temp.x.text.type() @ " / tostring: " temp.x.text " / is null: " @ ( temp.x.text == null ) );  
  
send"this.list.x / objecttype: " this.list.x.objecttype() @ " / type: " this.list.x.type() @ " / tostring: " this.list." / is null: " @ ( this.list.== null ) );    
  
send"this.list.x.text / objecttype: " this.list.x.text.objecttype() @ " / type: " this.list.x.text.type() @ " / tostring: " this.list.x.text " / is null: " @ ( this.list.x.text == null ) );      
}

function 
test(a)
{
  
this.list.(@ a).text "b";
  return 
this.list.(@ a);


send being just a simple function that PMs the given string. gets a result of:
PHP Code:

name               objecttype    type    tostring    isnull
temp
.p             TGraalVar        0         "5"         0
temp
.x             TGraalVar        0         "0"         1
temp
.x.text        TGraalVar       -1          ""         1
this
.list          TGraalVar       -1          ""         1
this
.list.x        TGraalVar       -1          ""         1
this
.list.x.text   TGraalVar        1         "b"         

Why is temp.x a numeric type and becomes "0", while at the same time being null, even though it supposedly is a reference to this.list.x?

Why can't temp.x.text access this.list.x.text? is that because this.list.x is null, thus doing temp.x = this.list.x; you set temp.x to null and not to a reference of an object that would look like { text: "b" } in JSON?

Is there any way to return such a reference? I might be able to return a string and makevar that or such... not sure if that would be of any help and I think i would have to makevar for each subvariable of this.list.x / temp.x I would try to access?

One way I seemingly found to do something is to do:
PHP Code:

  temp.this.list.x.link(); 

Which then makes that one result:
PHP Code:

name               objecttype    type    tostring    isnull
temp
.x.text        TGraalVar        1         "b"         

However, doing that also appears to mean that if i do temp.x.text = "a"; it won't change this.list.x.text, and I'm unaware how .link() acts here since the only documentation that describes its funcationality seems to say it is used in order to make sure arrays are passed without having their values copied.

Another way I found was to make this.list.x a TStaticVar, which would then allow temp.x to be non-null and temp.x.text to access this.list.x.text.

Which also leads to another question:
Is there a computational difference (storage, processing cost) between TStaticVar and TGraalVar aside the ability to destroy StaticVars?

I've heard StaticVar's without reference are cleaned up by GC at some point, but it still being advised to destroy them manually if you can.

When are TGraalVars collected? Immediately when they lack any reference? Or on a GC cycle too?
If the latter, wouldn't it be better to use TStaticVar wherever possible?

Matt 09-13-2014 11:57 AM

I'm no scripter, but for future help I'd gain access to the testbed server. A lot of on-deck help there.

Inari 09-13-2014 12:23 PM

Thanks, I do have access there already ^^


All times are GMT +2. The time now is 01:10 AM.

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