Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   TStaticVar names (https://forums.graalonline.com/forums/showthread.php?t=134257761)

Grey 01-25-2010 02:39 AM

TStaticVar names
 
Just curious whether TStaticVar's are supposed to have a name when created on Clientside because I can't get them to display.

PHP Code:

//#CLIENTSIDE
...
temp.variable "Fish";
temp.testing= new TStaticVar("Name_"@variable);
testing.one"things";
testing.two "stuff";
player.chat testing;
... 

Will output nothing.

But serverside..

PHP Code:

...
temp.variable "Fish";
temp.testing= new TStaticVar("Name_"@variable);
testing.one"things";
testing.two "stuff";
echo(
testing);
... 

Outputs Name_Fish

Immolate 01-25-2010 02:56 AM

Try using the 'name' variable to get it.

DustyPorViva 01-25-2010 03:12 AM

Indeed.

echo(testing.name)

Grey 01-25-2010 03:30 AM

Ahhh yep that did it. Thank you.

LoneAngelIbesu 01-25-2010 04:29 AM

So what is TStaticVar()'s parameter used for?

Grey 01-25-2010 05:06 AM

It makes it less than ideal to store objects in arrays as you can't use .index() and other built in functions (because an array of objects will all have the name ""). Would have to run through the array checking .name for each element.

cbk1994 01-25-2010 05:38 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1552252)
So what is TStaticVar()'s parameter used for?

The name.

PHP Code:

new TStaticVar("MyObject");
MyObject.variable value

Just make sure you keep a reference to the object somewhere or the garbage collector will eat it.

fowlplay4 01-25-2010 07:23 AM

Quote:

Originally Posted by Grey (Post 1552257)
It makes it less than ideal to store objects in arrays as you can't use .index() and other built in functions (because an array of objects will all have the name ""). Would have to run through the array checking .name for each element.

You can with player objects, so I'm not too sure how valid your statement actually is..

PHP Code:

echo(allplayers.index(findplayer("account"))); 

I've also done checks like..

PHP Code:

if (findplayer("account"in players) {
  
// stuff
}

if (
findweapon("-System"in player.weapons) {
  
// stuff


Edit: Further testing..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
temp.= new TStaticVar();
  
temp.a.val 2;
  
temp.= new TStaticVar();
  
temp.b.val 1;
  
temp.= new TStaticVar();
  
temp.c.val 3;
  
temp.objs.add(temp.a);
  
temp.objs.add("LOL MESSING U UP"); // It doesn't :)
  
temp.objs.add(temp.b);
  
temp.objs.add(temp.c);
  echo(
temp.objs.index(temp.b));
  if (
temp.c in temp.objs) {
    echo(
"this also works..");
  }


Now we all benefit for not having to use loops to compare objects :)

cbk1994 01-25-2010 07:29 AM

Quote:

Originally Posted by Grey (Post 1552257)
It makes it less than ideal to store objects in arrays as you can't use .index() and other built in functions (because an array of objects will all have the name ""). Would have to run through the array checking .name for each element.

Jerret is right. You can compare objects as objects, rather than comparing their names.

PHP Code:

temp.pl findPlayer("cbk1994");
temp.pl2 findPlayer("cbk1994");
temp.pl3 findPlayer("Grey");

echo(
pl == pl2); // 1
echo(pl == findPlayer("cbk1994")); // 1
echo(pl == pl3); // 0 

hence why you can also use "in" and functions like "index", as fowlplay said.

fowlplay4 01-25-2010 07:59 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1552252)
So what is TStaticVar()'s parameter used for?

For stuff like this..

PHP Code:

//#CLIENTSIDE

function onCreated() {
  
// Object-based Design
  
new TStaticVar("Tree") {
    
this.30;
    
this.30;
  };
  
temp.= new Tree();
  
temp.a.+= 5;
  
temp.= new Tree();
  
temp.b.+= 2;
  
temp.= new Tree();
  
temp.c.-= 2;
  
temp.c.-= 4;
  
// Display Values
  
echo(temp.a.a SPC temp.a.b);  // 35 30
  
echo(temp.b.a SPC temp.b.b);  // 30 32
  
echo(temp.c.a SPC temp.c.b);  // 28 26



Grey 01-25-2010 09:04 PM

Quote:

Originally Posted by fowlplay4 (Post 1552270)
Stuff

Appreciated you can do that if you have access to a var referencing the obj but what I was trying to do something along the lines of:

PHP Code:

//#CLIENTSIDE
function addToList(account) {
  
this.objs.add(new TStaticVar(@account));


function 
checkList() {
  return (
player.account in this.objs);


Which on the serverside would work. (If you changed checkList to be serverside friendly)

Was trying to see if I was doing it wrong somehow as if you output the array, rather than each of the objects having the name you'd assigned them, they all have blank names.

I'll just change the way its being handled but thanks guys

WhiteDragon 01-25-2010 11:38 PM

I'm pretty sure doing an equality check on objects implicitly casts them to their name and does a string comparison, which is pretty much worthless.

coreys 01-26-2010 12:33 AM

If all you're doing is storing the account names, then why would you need to use a TStaticVar(@account)?

Grey 01-26-2010 05:02 AM

Quote:

Originally Posted by coreys (Post 1552370)
If all you're doing is storing the account names, then why would you need to use a TStaticVar(@account)?

Why would you assume I'm only storing an account name if I'm trying to use a TStaticVar? :p

I was just using that as an example, each obj has stats and other info stored against it and are held on the server; info is passed to the client and a GUI is updated. User interaction is based off the current state of the objects and list of objects.

I don't know how great it is a method of doing it but I was hoping I could do checkList() or similiar to check the element actually existed, and control access to addition / removal of objects or data.

Inverness 01-26-2010 08:22 AM

Quote:

Originally Posted by WhiteDragon (Post 1552352)
I'm pretty sure doing an equality check on objects implicitly casts them to their name and does a string comparison, which is pretty much worthless.

Incorrect.

WhiteDragon 01-26-2010 08:49 PM

Quote:

Originally Posted by Inverness (Post 1552423)
Incorrect.

I just tested clientside, and it seems like I was right.
PHP Code:

temp.foo = new TStaticVar();
temp.foo.2;
  
temp.bar = new TStaticVar();
temp.bar.2;
  
echo(
temp.foo == temp.bar); // echos 0 


coreys 01-26-2010 09:02 PM

That doesn't exactly prove you are right.
My guess is behind the scenes TStaticVars and related objects have an id that it checks against with equality checks.

Immolate 01-26-2010 10:30 PM

Quote:

Originally Posted by Inverness (Post 1552423)
Incorrect.

The quality of your post would increase ten-fold if you explained why it was incorrect.

WhiteDragon 01-27-2010 03:18 AM

Quote:

Originally Posted by coreys (Post 1552465)
That doesn't exactly prove you are right.
My guess is behind the scenes TStaticVars and related objects have an id that it checks against with equality checks.

As far as I know, GS2 uses strings as its internal data type which everything gets converted to and stored as (think arrays).

I'm just saying that the name is likely what it is checking for a comparison, since it is a string that will always be there, and GS2 likes strings.

There is no way to really know what the comparison is unless Stefan tells us, or someone writes a test case that is explicit enough.

I certainly wouldn't make use of any of the code posted in this thread because I don't know exactly what it is doing and it would also be unclear and potentially misleading to anyone else who looks at the code.


All times are GMT +2. The time now is 08:38 AM.

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