Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-13-2014, 11:26 AM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
Question 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:
Graal Script 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:
Graal Script 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:
Graal Script Code:
  temp.this.list.x.link(); 
Which then makes that one result:
Graal Script 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?

Last edited by Inari; 09-13-2014 at 02:31 PM.. Reason: script formatting
Reply With Quote
  #2  
Old 09-13-2014, 12:57 PM
Matt Matt is offline
iZone Administrator
Matt's Avatar
Join Date: Apr 2005
Location: United States
Posts: 2,690
Matt is a jewel in the roughMatt is a jewel in the rough
Send a message via Skype™ to Matt
I'm no scripter, but for future help I'd gain access to the testbed server. A lot of on-deck help there.
__________________
Need Playerworld or Account support?
GraalOnline/Toonslab Support Center
Reply With Quote
  #3  
Old 09-13-2014, 01:23 PM
Inari Inari is offline
Registered User
Join Date: Sep 2014
Posts: 47
Inari is on a distinguished road
Thanks, I do have access there already
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 09:42 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.