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 03-20-2015, 09:55 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Hmm, I know I have used this before. But I think I lacked some understanding. Is there anyone that can explain any differences between using a TStaticVar() vs something like savevarstoarray() and loadvarsfromarray() ? In the past I have used both of them to preserve variables such as temp.obj.var.
Reply With Quote
  #2  
Old 03-21-2015, 02:36 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by scriptless View Post
Hmm, I know I have used this before. But I think I lacked some understanding. Is there anyone that can explain any differences between using a TStaticVar() vs something like savevarstoarray() and loadvarsfromarray() ? In the past I have used both of them to preserve variables such as temp.obj.var.
loadvarsfromarray and savevarstoarray is used for serialization. Useful for when you want to send an object over a method that doesn't support them or save it to a file.

e.g. triggers

PHP Code:
function onCreated() {
  
temp.ex.123;
  
temp.ex.234;
  
temp.ex.345;
  
temp.data temp.ex.savevarstoarray(false);
  
findplayer("fowlplay4").triggerclient("weapon"this.name"data"temp.data);
}

//#CLIENTSIDE

function onActionClientSide() {
  if (
params[0] == "data") {
    
temp.data params[1];
    
temp.ex.loadvarsfromarray(temp.data);
    echo(
temp.ex.a SPC temp.ex.b SPC temp.ex.c); // echos 123 234 345
  
}

__________________
Quote:
Reply With Quote
  #3  
Old 03-21-2015, 07:47 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
Quote:
Originally Posted by fowlplay4 View Post
loadvarsfromarray and savevarstoarray is used for serialization. Useful for when you want to send an object over a method that doesn't support them or save it to a file.

e.g. triggers

PHP Code:
function onCreated() {
  
temp.ex.123;
  
temp.ex.234;
  
temp.ex.345;
  
temp.data temp.ex.savevarstoarray(false);
  
findplayer("fowlplay4").triggerclient("weapon"this.name"data"temp.data);
}

//#CLIENTSIDE

function onActionClientSide() {
  if (
params[0] == "data") {
    
temp.data params[1];
    
temp.ex.loadvarsfromarray(temp.data);
    echo(
temp.ex.a SPC temp.ex.b SPC temp.ex.c); // echos 123 234 345
  
}

Hmm, well is there any instance that I would be forced to use TStaticVar, or better to use? I generally find myself just using vars like I mentioned. Not sure if that is good practice, or if I should look more into using TStaticVar's?

Sorry if it sounds like a noob question just the overwhelming lack of documentation for GScript2 makes understanding somewhat difficult at times.

Also, thanks FP4 for the reply. Ans also not trying to hijack the thread. It's still relevant to discussion of the TStaticVar.
Reply With Quote
  #4  
Old 03-23-2015, 02:25 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by scriptless View Post
Hmm, well is there any instance that I would be forced to use TStaticVar, or better to use? I generally find myself just using vars like I mentioned. Not sure if that is good practice, or if I should look more into using TStaticVar's?

Sorry if it sounds like a noob question just the overwhelming lack of documentation for GScript2 makes understanding somewhat difficult at times.

Also, thanks FP4 for the reply. Ans also not trying to hijack the thread. It's still relevant to discussion of the TStaticVar.
If you don't want to constantly serialize your dictionary ("object") every time you want to pass it around, you can use a TStaticVar instead. This can be moderately faster and easier to read (less boilerplate).

This won't work going across serverside/clientside, of course -- you'll need to serialize in this case.

Also iirc savevarstoarray on a non-TStaticVar will include the random built-in object properties (stuff like initialized, joinedclasses, timeout, ...) in at least some cases. But I can't remember if that's true or not.
__________________
Reply With Quote
  #5  
Old 03-23-2015, 03:27 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by cbk1994 View Post

Also iirc savevarstoarray on a non-TStaticVar will include the random built-in object properties (stuff like initialized, joinedclasses, timeout, ...) in at least some cases. But I can't remember if that's true or not.
You're right.
__________________
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 02:41 AM.


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