Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   getstringkeys() and loadvars() (https://forums.graalonline.com/forums/showthread.php?t=81534)

Frankie 08-28-2008 03:56 PM

getstringkeys() and loadvars()
 
I'm not sure how to use the 2 together.

PHP Code:

function onCreated()
{
  
temp.gang.loadvars("gangs/Los Carteles.txt");
  for (
temp.igetstringkeys("rights-"))
  {
  }


It's hard to put in words, but I know in a database you can do
PHP Code:

with (findNPC("database stuff"))
{
  for (
temp.igetstringkeys("stuff"))
  {
  }


which will get the strings in the database.
I'm just not sure how to get the strings in the text file.

DustyPorViva 08-28-2008 03:59 PM

I'm not terribly familiar with this, but...
PHP Code:

function onCreated()
{
  
temp.gang.loadvars("gangs/Los Carteles.txt");
  for (
temp.itemp.gang.getstringkeys("rights-"))
  {
  }


?

Frankie 08-28-2008 04:00 PM

I've tried that :(

Script: Function gang.getstringkeys not found at line 69 in script of *Frankie

Chompy 08-28-2008 04:11 PM

getstringkeys() can't but used directly on an object (obj.getstringkeys())
Use it inside a with() scope.

And, for the files, use obj.getDynamicVarNames();

PHP Code:

function onCreated() {
  
temp.file.loadvars("gangs/PizzaClan.txt");
  
  
temp.gang_PizzaClan = new TStaticVar();

  for(
temp.var : temp.file.getDynamicVarNames()) {
    
temp.gang_PizzaClan.(@var) = temp.file.(@var);
  }

  
temp.keys 0;
  
with(temp.gang_PizzaClan) {
    
temp.keys getstringkeys("variable_prefix");
  }


Just a fast mockup, but something like that would work I guess

xXziroXx 08-28-2008 04:20 PM

Quote:

Originally Posted by Chompy (Post 1418613)
getstringkeys() can't but used directly on an object (obj.getstringkeys())
Use it inside a with() scope.

No. :oo:

PHP Code:

temp.string_foobar "lawl";
temp.string_lolwat "baz";
for (
temp.foogetstringkeys("temp.string_")) {
  echo(
foo SPC "[" makevar("temp.string_" foo) @ "]");


Result:

PHP Code:

foobar [lawl]
lolwat [baz


Chompy 08-28-2008 04:29 PM

Quote:

Originally Posted by xXziroXx (Post 1418618)
No. :oo:

PHP Code:

... 

Result:

PHP Code:

... 


Where in your script are you doing object.getstringkeys() though? ;o

I might of worded it wrong, as my vocabulary isn't that big in English :p
But I did put 'obj.getstringkeys()' in parenthesises :p

xXziroXx 08-28-2008 04:40 PM

If I wanted to do it with an object, I would do:


PHP Code:

temp.obj findNPC("foobarbaz");
obj.string_foobar "lawl";  // Just to show a string example.
obj.string_lolwat "baz";  // Just to show a string example.
for (temp.foogetstringkeys("obj.string_")) {
  echo(
foo SPC "[" makevar("obj.string_" foo) @ "]");



Chompy 08-28-2008 04:43 PM

Quote:

Originally Posted by xXziroXx (Post 1418631)
If I wanted to do it with an object, I would do:


PHP Code:

temp.obj findNPC("foobarbaz");
obj.string_foobar "lawl";  // Just to show a string example.
obj.string_lolwat "baz";  // Just to show a string example.
for (temp.foogetstringkeys("obj.string_")) {
  echo(
foo SPC "[" makevar("obj.string_" foo) @ "]");



Hmm, you're right, but you can't do obj.getstringkeys() :p

But yeah.. I probably read through your script to fast :)

xXziroXx 08-28-2008 04:45 PM

Quote:

Originally Posted by Chompy (Post 1418636)
Hmm, you're right, but you can't do obj.getstringkeys() :p

Agreed. I also didn't read your post too well, I was under the impression that you meant something like this for a while:

PHP Code:

with (getstringkeys("foobar")) {
...



Chompy 08-28-2008 05:02 PM

Quote:

Originally Posted by xXziroXx (Post 1418638)
Agreed. I also didn't read your post too well, I was under the impression that you meant something like this for a while:

PHP Code:

... 


:p hehe

TheStan 08-28-2008 07:30 PM

Booyah!

PHP Code:

function onCreated() {
  
this.test();
}
public function 
test() {
  
temp.file = new TStaticVar();
  
temp.file.var_1 "moo";
  
temp.file.var_2 46;
  
  
with (temp.file) {
    
temp.keys getstringkeys("this.var_");
  }
  echo(
"Keys: " temp.keys);



Frankie 08-28-2008 09:28 PM

PHP Code:

function onCreated() {
  
this.test();
}
public function 
test() {
  
temp.file = new TStaticVar();
  
temp.file.loadvars("gangs/Los Carteles.txt");
  
  
with (temp.file) {
    
temp.keys getstringkeys("this.rights-");
    
    for (
temp.itemp.keys)
    {
      if (
this.("rights-" temp.i)[7] == 1)
      {
        echo(
temp.i);
      }
    }
  }


basically I was trying to cycle through all the accounts and their rights and find out if they had a specific right (leader right)

thanks :D

Chompy 08-28-2008 09:39 PM

Quote:

Originally Posted by Frankie (Post 1418733)
PHP Code:

... 

basically I was trying to cycle through all the accounts and their rights and find out if they had a specific right (leader right)

thanks :D

Also, loops inside with() aren't optimized :p Just thought you would want to know =p

xXziroXx 08-28-2008 09:43 PM

makevar("this.rights-" @ temp.i) instead of this.("rights-" @ temp.i) :rolleyes:

Frankie 08-28-2008 11:30 PM

Quote:

Originally Posted by Chompy (Post 1418741)
Also, loops inside with() aren't optimized :p Just thought you would want to know =p

it doesn't work if I take the for() loop out of the with()

cbk1994 08-28-2008 11:32 PM

Quote:

Originally Posted by xXziroXx (Post 1418742)
makevar("this.rights-" @ temp.i) instead of this.("rights-" @ temp.i) :rolleyes:

It shouldn't make a difference though, should it? I prefer this.(@ "blah").

Inverness 08-28-2008 11:42 PM

Quote:

Originally Posted by cbk1994 (Post 1418804)
It shouldn't make a difference though, should it? I prefer this.(@ "blah").

It makes a difference if there are any dots in temp.i... I think.

xXziroXx 08-29-2008 12:18 AM

this.(STUFF HERE) should only be used with dynamic variables, and makevar("this." @ STUFF HERE)) with normal strings. Otherwise they will spontaneously behave odd from time to time, and maybe they're not supposed to do that, but I've dealt a lot with this particular issue over the last years.

Skyld 08-29-2008 12:32 AM

Quote:

Originally Posted by xXziroXx (Post 1418831)
this.(STUFF HERE) should only be used with dynamic variables, and makevar("this." @ STUFF HERE)) with normal strings. Otherwise they will spontaneously behave odd from time to time, and maybe they're not supposed to do that, but I've dealt a lot with this particular issue over the last years.

I use this.(stuff here) all the time because I hate hate hate how messy code looks when using makevar(), and I have never had any issues.

Frankie 08-29-2008 02:02 AM

my post got cut off because Chris started a new page in case you guys didn't see :[

Quote:

Originally Posted by Chompy (Post 1418741)
Also, loops inside with() aren't optimized :p Just thought you would want to know =p

it doesn't work if I take the for() loop out of the with()


it's just making me curious now that he said that.

TheStan 08-29-2008 03:11 AM

BOOYAH!

PHP Code:

function onCreated() {
  
this.test();
}
public function 
test() {
  
temp.file = new TStaticVar();
  
temp.file.loadvars("gangs/Los Carteles.txt");
  
  
with (temp.file) {
    
temp.keys getstringkeys("this.rights-");
  } 
  for (
temp.itemp.keys)
  {
    if (
temp.file.("rights-" temp.i)[7] == 1)
    {
      echo(
temp.i);
    }
  }


Should work rougly.

Inverness 08-29-2008 03:30 AM

Quote:

Originally Posted by TheStan (Post 1418869)
BOOYAH!

PHP Code:

function onCreated() {
  
this.test();
}
public function 
test() {
  
temp.file = new TStaticVar();
  
temp.file.loadvars("gangs/Los Carteles.txt");
  
  
with (temp.file) {
    
temp.keys getstringkeys("this.rights-");
  } 
  for (
temp.itemp.keys)
  {
    if (
temp.file.("rights-" temp.i)[7] == 1)
    {
      echo(
temp.i);
    }
  }


Should work rougly.

If that was C++ you'd have a memory leak. And you forgot the @ before "rights-" in the loop.

LoneAngelIbesu 08-29-2008 03:37 AM

Quote:

Originally Posted by Inverness (Post 1418876)
If that was C++ you'd have a memory leak. And you forgot the @ before "rights-" in the loop.

Thank God it's not C++. :D

Inverness 08-29-2008 03:53 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1418877)
Thank God it's not C++. :D

I wouldn't say that.

Having a server crash due to Stan's scripting error would be popcorn-worthy.

TheStan 08-29-2008 04:32 AM

Quote:

Originally Posted by Inverness (Post 1418884)
I wouldn't say that.

Having a server crash due to Stan's scripting error would be popcorn-worthy.

That's all well and funny but you seem to be forgetting one thing had you been paying close attention Invern...that isn't my script. I copied and pasted and just moved the for loop and changed "this.(@ blah)" to "temp.file.(@ black)" any other errors are of his property.

Frankie 08-29-2008 04:39 AM

I don't understand what temp.file.("rights-" @ temp.i) is any different from temp.file.(@ "rights-" @ temp.i

LoneAngelIbesu 08-29-2008 05:00 AM

Quote:

Originally Posted by Frankie (Post 1418892)
I don't understand what temp.file.("rights-" @ temp.i) is any different from temp.file.(@ "rights-" @ temp.i

PHP Code:

function onCreated() {
  
temp."foo";
  
temp.i.rights_foo "bar";
  echo(
temp.i.(@ "rights_" temp.e));
  echo(
temp.i.("rights_" temp.e));


Returns:
PHP Code:

Weapon/GUI-script _DylanTest2 added/updated by LoneAngelIbesu
bar
bar 

So, I don't see the difference either.

TheStan 08-29-2008 05:04 AM

There is no difference according to code. The different is preference. :/

cbk1994 08-29-2008 05:07 AM

Quote:

Originally Posted by Frankie (Post 1418892)
I don't understand what temp.file.("rights-" @ temp.i) is any different from temp.file.(@ "rights-" @ temp.i

I'm actually not sure ... that's how I've always seen it done though, so that's how I've done it. I wonder why people do it (if it really DOES make a difference).

coreys 08-29-2008 05:42 AM

Quote:

Originally Posted by TheStan (Post 1418890)
That's all well and funny but you seem to be forgetting one thing had you been paying close attention Invern...that isn't my script. I copied and pasted and just moved the for loop and changed "this.(@ blah)" to "temp.file.(@ black)" any other errors are of his property.

Then don't present it as such?
Say "Hey, you should organize it like this" rather than "Hey, this should work."

Inverness 08-29-2008 05:52 AM

Originally,

("test" @ "pancake") is returning a string because first part is string. And this."testpancake" wouldn't work obviously.
(@ "test" @ "pancake") is returning a variable name because first part was empty.

Though it seems like Stefan has compensated for that now since doing that in a variable works either way. Either that or the reason it was originally done was forgotten by me.

If Stefan could tell us whats up that would be nice.

cbk1994 08-29-2008 06:09 AM

I don't like how Stefan makes up for things that people make errors in; e.g. profiles as strings. I had no idea they were actually supposed to be objects. If he hadn't done that, I would have of course used the object.

Inverness 08-29-2008 05:34 PM

Its why I want a GS3 that is more stricter and more Object-Oriented and doesn't allow any of the old GS1.

TheStan 08-29-2008 05:58 PM

Quote:

Originally Posted by Inverness (Post 1418970)
Its why I want a GS3 that is more stricter and more Object-Oriented and doesn't allow any of the old GS1.

orly?

DrakilorP2P 08-29-2008 06:40 PM

Quote:

Originally Posted by Inverness (Post 1418970)
Its why I want a GS3 that is more stricter and more Object-Oriented and doesn't allow any of the old GS1.

I'd rather have something well defined and documented, like Lua, Squirrel, Python, GameMonkey, Lisp, some dialect of BASIC, Perl, awk, ECMAScript, Java, PHP, Ruby or Tcl.


Quote:

Originally Posted by TheStan (Post 1418980)
orly?

I am thoroughly offended by this horrible abuse of not only the English language, but some cultural references as well.

TheStan 08-29-2008 06:45 PM

Quote:

Originally Posted by DrakilorP2P (Post 1418993)
I am thoroughly offended by this horrible abuse of not only the English language, but some cultural references as well.

Just kidding there Drakilor.

Codein 08-30-2008 12:05 AM

Quote:

Originally Posted by TheStan (Post 1418995)
Just kidding there Drakilor.

Everyone seems to be offended these days xD. I personally use something like this:

PHP Code:

this.("prefix_" varname) = "foo"


Inverness 08-30-2008 02:44 AM

Quote:

Originally Posted by DrakilorP2P (Post 1418993)
I'd rather have something well defined and documented, like Lua, Squirrel, Python, GameMonkey, Lisp, some dialect of BASIC, Perl, awk, ECMAScript, Java, PHP, Ruby or Tcl.

If Stefan were to use a well established language; which is what I would prefer, then I say to use Stackless Python.

Not allowed to give you a URL (most retarded rule ever) so search on google for "why stackless" and pick first result.

Of course if Stefan wanted to use this then he would need to be implementing some sort of security features and all that stuff. The source code is available for that.

I don't think Stefan has time to do anything like that however, even if I think it would be beneficial in the long run.

cbk1994 08-30-2008 05:48 AM

GS2 is a pretty awesome language; it's very easy to learn (compared to other languages), and you can do a lot of stuff much easier than with other languages. While the price may be speed of running the code, it's still a very good starting language, and I think it is fine for Graal. I don't see any need to change it to a completely different language, just listen to some of the suggestions (**custom objects**, catchevent, etc).

Inverness 08-30-2008 06:10 AM

Quote:

Originally Posted by cbk1994 (Post 1419104)
GS2 is a pretty awesome language; it's very easy to learn (compared to other languages), and you can do a lot of stuff much easier than with other languages. While the price may be speed of running the code, it's still a very good starting language, and I think it is fine for Graal. I don't see any need to change it to a completely different language, just listen to some of the suggestions (**custom objects**, catchevent, etc).

Python is an awesome language, easy to learn compared to others, and you can do a lot of stuff much easier than with other languages. And there aren't weird things like only built-in variables being case sensitive and odd leftover functions for compatibility, variables without prefix being global instead of local to the function like in most other languages.


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

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