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 05-04-2009, 04:10 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Static variables

Do they exist?
Reply With Quote
  #2  
Old 05-04-2009, 04:25 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
TStaticVar :|
Reply With Quote
  #3  
Old 05-04-2009, 04:42 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Loriel View Post
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

Reply With Quote
  #4  
Old 05-04-2009, 05:18 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
C function scope static variables are pretty ****ty, at least ask for C++ static members.
Reply With Quote
  #5  
Old 05-04-2009, 05:22 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
Store them in a server. or a DBNPC if it's that important I guess.
__________________
Quote:
Reply With Quote
  #6  
Old 05-04-2009, 05:26 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by Loriel View Post
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.
Reply With Quote
  #7  
Old 05-04-2009, 05:34 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________
Reply With Quote
  #8  
Old 05-04-2009, 05:40 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
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

__________________
Quote:
Reply With Quote
  #9  
Old 05-04-2009, 05:44 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by fowlplay4 View Post
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.
__________________
Reply With Quote
  #10  
Old 05-04-2009, 05:59 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Good idea, Inverness. I've got an idea brewing which is based of what you've said.
Reply With Quote
  #11  
Old 05-04-2009, 07:41 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Inverness View Post
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
__________________
Reply With Quote
  #12  
Old 05-04-2009, 09:17 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by Inverness View Post
Edit: I also have to say that I think GScript should be scrapped and replaced with Lua. GScript is too inconsistent.
Horrible idea.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #13  
Old 05-04-2009, 09:32 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by xXziroXx View Post
Horrible idea.
Says the person who only knows GScript.
__________________
Reply With Quote
  #14  
Old 05-05-2009, 12:35 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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).
Reply With Quote
  #15  
Old 05-05-2009, 03:10 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Inverness View Post
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.
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 11:33 PM.


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