Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Feature request (https://forums.graalonline.com/forums/forumdisplay.php?f=194)
-   -   discard #varname#; (https://forums.graalonline.com/forums/showthread.php?t=83520)

Tyhm 01-05-2009 04:56 PM

discard #varname#;
 
A minor item for further cranking up the efficiency of complex NPCs. Limits the scope of a variable by declaring it will no longer be used. For instance:

for(this.i=0;this.i<playerscount;this.i++){
...
}
discard this.i; //implicit

because you're unlikely to care that this.i still =playerscount an hour later. Would avoid the usual scripting mess of having one NPC with 70 variables, all of which were intended to be temporary but are still holding floating-point data; granted, that's only 70bytes, but it adds up.

xXziroXx 01-05-2009 05:02 PM

Or you can use temp. variables that clear themselves after the current function scope.

Tyhm 01-05-2009 10:06 PM

Oops, well said, nm...how did I miss those?...

cbk1994 01-05-2009 11:38 PM

You could also declare

PHP Code:

this.null

and the variable is then forgotten.

Crow 01-06-2009 03:15 PM

Quote:

Originally Posted by cbk1994 (Post 1454870)
You could also declare

PHP Code:

this.null

and the variable is then forgotten.

Wouldn't bet on that one. Vars you have set to nil or null in the past still appear in database npcs, too. When you set them to an empty string, they dont.

Chompy 01-06-2009 03:47 PM

Quote:

Originally Posted by Crow (Post 1455056)
Wouldn't bet on that one. Vars you have set to nil or null in the past still appear in database npcs, too. When you set them to an empty string, they dont.

clearEmptyVars();

Crow 01-06-2009 05:26 PM

Quote:

Originally Posted by Chompy (Post 1455058)
clearEmptyVars();

I still remember Stefan's answer when I tried this and it didn't work. His "hm" had like 7 Ms.

Skyld 01-06-2009 06:59 PM

You can also use rungarbagecollector() to clear any links to non-existent variables or objects, although the engine should normally do this eventually.

cbk1994 01-07-2009 03:33 AM

Quote:

Originally Posted by Crow (Post 1455056)
Wouldn't bet on that one. Vars you have set to nil or null in the past still appear in database npcs, too. When you set them to an empty string, they dont.

That's weird. Probably would be removed when the garbage collector runs, as Skyld said.

In Java you can destroy an object by destroying all links to that object; I assumed the same would work in GS2, but I guess not, or not reliably.

xXziroXx 01-07-2009 05:58 PM

Quote:

Originally Posted by Crow (Post 1455056)
Wouldn't bet on that one. Vars you have set to nil or null in the past still appear in database npcs, too. When you set them to an empty string, they dont.

Wrong. Variables/arrays disappear when set to NULL, strings disappear when set to "" (empty string), and TStaticVar's when clearVars()'ed. At least if my memory serves me right.

Chompy 01-07-2009 06:59 PM

Quote:

Originally Posted by xXziroXx (Post 1455279)
Wrong. Variables/arrays disappear when set to NULL, strings disappear when set to "" (empty string), and TStaticVar's when clearVars()'ed. At least if my memory serves me right.

This doesn't always apply to variables when working with database npcs.
This is what clearEmptyVars(); is good for, clearing all empty vars (0 as value for example) in the current object scope.

Crow 01-07-2009 06:59 PM

Quote:

Originally Posted by xXziroXx (Post 1455279)
Wrong. Variables/arrays disappear when set to NULL, strings disappear when set to "" (empty string), and TStaticVar's when clearVars()'ed. At least if my memory serves me right.

If you are refering to database npcs as well, you are still somewhat wrong. I thought it would make sense that variables disappear when setting them to nil, so I did exactly that. Before I did it, the variable was holding an integer number. And if I recall correctly, it's the same problem with arrays. But it works for me all the time using an empty string. Don't ask me why, I don't even bother anymore, I already accepted all the weird stuff Graal has to offer a long time ago.


All times are GMT +2. The time now is 05:47 AM.

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