Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Static variables (https://forums.graalonline.com/forums/showthread.php?t=85436)

Codein 05-04-2009 04:10 PM

Static variables
 
Do they exist?

Loriel 05-04-2009 04:25 PM

TStaticVar :|

Codein 05-04-2009 04:42 PM

Quote:

Originally Posted by Loriel (Post 1488985)
TStaticVar :|

Not exactly what I meant. I meant like the way the static keyword works in C functions. As you probably know, so that variables retain their values even after the function's end, but can't be accessed script-wide, just in that function.

For example:

PHP Code:

function onCreated() {
 for (
temp.0temp.10temp.i++) {
  echo(
staticTest());
 }
}

function 
staticTest() {
  if (
temp.staticVar == NULLtemp.staticVar = new TStaticVar();
  
temp.staticVar.var1++;
  return 
temp.staticVar.var1;


outputs this:

PHP Code:

1
1
1
1
1
1
1
1
1



Loriel 05-04-2009 05:18 PM

C function scope static variables are pretty ****ty, at least ask for C++ static members.

fowlplay4 05-04-2009 05:22 PM

Store them in a server. or a DBNPC if it's that important I guess.

Codein 05-04-2009 05:26 PM

Quote:

Originally Posted by Loriel (Post 1489003)
C function scope static variables are pretty ****ty, at least ask for C++ static members.

Sounds like there'd need to be some kind of class implementation (which I'd love)? I'm not sure. I know little about C++ and C for that matter. What I was asking for seemed best represented by what they have in C.

Inverness 05-04-2009 05:34 PM

Just use global or object variables.

Edit: I also have to say that I think GScript should be scrapped and replaced with Lua. GScript is too inconsistent.

fowlplay4 05-04-2009 05:40 PM

You could have a DB NPC called Static Variables or something..

PHP Code:

function onCreated() {
  
staticvar this;


Then in other scripts just reference it like so:

PHP Code:

function onCreated() {
  
staticvar.crazyexample 100;
  echo(
staticvar.crazyexample); // 100 should appear on RC



Inverness 05-04-2009 05:44 PM

Quote:

Originally Posted by fowlplay4 (Post 1489010)
You could have a DB NPC called Static Variables or something..

PHP Code:

function onCreated() {
  
staticvar this;


Then in other scripts just reference it like so:

PHP Code:

function onCreated() {
  
staticvar.crazyexample 100;
  echo(
staticvar.crazyexample); // 100 should appear on RC



I wasn't aware that DBNPCs were guaranteed to be accessible on clientside at all times.

I would suggest having a system weapon create a TStaticVar.

Codein 05-04-2009 05:59 PM

Good idea, Inverness. I've got an idea brewing which is based of what you've said.

Crow 05-04-2009 07:41 PM

Quote:

Originally Posted by Inverness (Post 1489008)
Edit: I also have to say that I think GScript should be scrapped and replaced with Lua. GScript is too inconsistent.

I love you <3

xXziroXx 05-04-2009 09:17 PM

Quote:

Originally Posted by Inverness (Post 1489008)
Edit: I also have to say that I think GScript should be scrapped and replaced with Lua. GScript is too inconsistent.

Horrible idea.

Inverness 05-04-2009 09:32 PM

Quote:

Originally Posted by xXziroXx (Post 1489052)
Horrible idea.

Says the person who only knows GScript.

Admins 05-05-2009 12:35 AM

Please stop those off-topic nonsense comments.

Static function-variables are quite interesintg in C/C++ although at the end they are just global variables. So we don't necessary require them, although it's true that it's sometimes good to have some real secured placed where you know that other scripts cannot interfere (another reason for the idea of private variables).

Skyld 05-05-2009 03:10 PM

Quote:

Originally Posted by Inverness (Post 1489008)
Edit: I also have to say that I think GScript should be scrapped and replaced with Lua. GScript is too inconsistent.

WILL NOT HAPPEN.

Now that we've cleared that up, please move on with your life.


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

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