Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Named Array Indexes (https://forums.graalonline.com/forums/showthread.php?t=76192)

Inverness 08-10-2007 07:44 AM

Named Array Indexes
 
I'm sure most scripters should know of that array format used when saving object variables to array.
array = {"var1=value1", "var2=value2", "var3=value3", "var4=value4"};

Was wondering if a little feature could be added where if you did:
array["var2"] = "newvalue";
It would correctly replace the proper index with the new value after the equal sign. They would also be read in the same manner.

Skyld 08-10-2007 01:37 PM

Associative arrays?

In reality it would be just as easy to use a TStaticVar or something.

zokemon 08-10-2007 02:54 PM

Quote:

Originally Posted by Skyld (Post 1338722)
Associative arrays?

In reality it would be just as easy to use a TStaticVar or something.

Yes, but that wouldn't work if you were dealing with clientr and client variables. You would have to load the vars from the client/clientr array into another TStaticVar object which would take a slight bit more time/cpu/memory then doing what Inverness is suggesting. I still think this feature isn't that important though since it's really rare for a case like I am describing.

Inverness 08-11-2007 09:37 AM

Client vars are too limited by character to be doing things like that.

zokemon 08-11-2007 11:11 AM

Quote:

Originally Posted by Inverness (Post 1338986)
Client vars are too limited by character to be doing things like that.

Client vars are not limited to a character length!
It is only the act of doing /open and applying changes that your vars get trimmed. This has nothing to do with the fact that they are client vars but rather is because anything in the "flags" section of /open gets clipped like such.

If you just never use /open (such as scripting your own player editor) then you don't need to worry about such stupid misconceptions. I personally never ever have to use /open for anything what-so-ever.

xXziroXx 08-11-2007 01:51 PM

Quote:

Originally Posted by zokemon (Post 1338991)
I personally never ever have to use /open for anything what-so-ever.

Me either. I stopped doing that when I realized that /open cuts of client and clientr strings, and the serverflags window cuts of server and serverr flags.

High five! :fro:

Inverness 08-11-2007 07:21 PM

Valikorlia does not revolve around me, there are plenty of other staff who are going to have to use open at some time or another. And I'm not going to prevent them from doing it just because of my fancy scripting.

The character limit needs when using the /open command needs to be removed, period.

I'm not going to script my own player editor because you should not need to get on client to do that, that is what RC is for.

xXziroXx 08-11-2007 07:43 PM

*sigh* Here we go again..

Inverness 08-21-2007 09:41 AM

Quote:

Originally Posted by xXziroXx (Post 1339080)
*sigh* Here we go again..

If you don't want to hear what I have to say stop bringing it up, I'm not going to compromise by ignoring a perfectly good feature of the RC thats been in use for years.
Quote:

Originally Posted by Skyld
Associative arrays?

In reality it would be just as easy to use a TStaticVar or something.

You can't convert objects to strings in a simple way, arrays already are strings.

Inverness 10-28-2007 03:25 AM

*Bump*

I have renewed interest in this feature.

Novo 10-28-2007 03:59 AM

array = {{"key", "value"}, {"key", "value"}}

PHP Code:

function getIndexWithName( array, name )
{
  for ( 
temp.cell: array )
  {
    if ( 
temp.cell[0] == name )
      return 
temp.cell[1];
  }
  return 
null;


You can create your own functions of the sort...
PHP Code:

function indexOf( array, name )
{
  for ( 
0< array.size(); ++ )
    if ( array[
i][0] == cellName )
      return 
i;
  return -
1;
}

function 
setCellWithName( array, namevalue )
{
  if ( 
indexOf( array, name ) != -)
    array[ 
indexOf( array, name ) ][1] = value;

  return array;


... etc, etc...

Inverness 10-28-2007 08:10 AM

Well duh.

And I prefer it would work like:

array = {"key=value", "key=value"};

Since that is how objects are saved to arrays and such, its more of a standard.

Doing array["key"] = value looks much nicer though and would be simple enough to implement. Python makes use of it well.

Novo 10-28-2007 09:17 AM

Yes. Sadly, this isn't Python or PHP or any other languages that make use of associative arrays. Taken into considering that we're talking about GScript... I would say that it isn't part of the language...

I provided you a way to do this... You can easily call functions, but right now, you just want it to LOOK pretty... Which isn't the purpose of programming language... It just converts it back to the very same thing.

And implementing that would mean you'd have to change the lexical of the language... And that's not pretty. There are ways that an associative array can be 'simulated'... So I don't see any more purpose to this than for aesthetic reasons. Stefan is busy enough fixing things that ARE useful. For instance, new features.

Inverness 10-28-2007 09:42 AM

Quote:

Originally Posted by Novo (Post 1355041)
Yes. Sadly, this isn't Python or PHP or any other languages that make use of associative arrays.

Whats your point? I can't tell if you're being sarcastic or not.
Quote:

Originally Posted by Novo (Post 1355041)
Taken into considering that we're talking about GScript... I would say that it isn't part of the language...

Which is why I'm asking for it.
Quote:

Originally Posted by Novo (Post 1355041)
I provided you a way to do this... You can easily call functions, but right now, you just want it to LOOK pretty... Which isn't the purpose of programming language... It just converts it back to the very same thing.

GScript isn't a programming language. And if thats your opinion explain why Python has this feature since you could easily make functions as you said.
Quote:

Originally Posted by Novo (Post 1355041)
And implementing that would mean you'd have to change the lexical of the language... And that's not pretty.

I wont take your word for it since you're not Stefan, sorry.
Quote:

Originally Posted by Novo (Post 1355041)
There are ways that an associative array can be 'simulated'... So I don't see any more purpose to this than for aesthetic reasons.

Well, why not go and ask those Python people why they added a dictionary data type.
Quote:

Originally Posted by Novo (Post 1355041)
Stefan is busy enough fixing things that ARE useful. For instance, new features.

Stefan isn't very good at documentation, if I were him I would be keeping a public list of things that are being worked on, considered, denied, or completed for the next version.

I asked for the feature because it would be an easy solution to an irritation, and I'm not going to make functions and bother joining them everytime I use the feature when they could be done much better this way. Using functions would be more troublesome than giving the data specified indexes.

Such a feature would also be good for those newer to scripting/programming.

I don't think you're doing a good job of explaining why not to add a simple feature present in other languages.

xAndrewx 10-28-2007 09:53 AM

hmm I doubt Stefan will add it. Stop being an ******* and use the alternative

Inverness 10-28-2007 11:23 AM

Quote:

Originally Posted by xAndrewx (Post 1355045)
hmm I doubt Stefan will add it. Stop being an ******* and use the alternative

Make me. :D

I already explained why the alternative was unfavorable, and if you can't read posts and respond properly you will be ignored.

xAndrewx 10-28-2007 11:24 AM

sado

Infact, instead of trying to help you, just wait for Stefan to release this feature ^^

Admins 10-28-2007 12:34 PM

Well you can give array members names now and use obj.getArrayMember(name) although it is not really recommended since it is much slower than using normal variables (obj.(@mycustomvarname)), it is mainly used for xml stuff.

In Flash script (and Javascript?) they just map array["key"] to array.key

I also beg to differ, Graal IS a programming language

Crow 10-28-2007 12:52 PM

Quote:

Originally Posted by Stefan (Post 1355051)
I also beg to differ, Graal IS a programming language

I would call it scripting language, since you cannot write your own programs with gscript.

Twinny 10-28-2007 12:56 PM

Quote:

Originally Posted by Crow (Post 1355052)
I would call it scripting language, since you cannot write your own programs with gscript.

Seconded.

xAndrewx 10-28-2007 12:57 PM

look in to it deeper @ Crow. You'll see that you're wrong.

Crow 10-28-2007 01:13 PM

Quote:

Originally Posted by xAndrewx (Post 1355054)
look in to it deeper @ Crow. You'll see that you're wrong.

O, so you can now compile executables with gscript? I didnt know before, you should teach me how.

Twinny 10-28-2007 01:51 PM

I think it's more of a scripting language. Its limited to graal much like javascript is limited to a web browser.

Skyld 10-28-2007 02:06 PM

Quote:

Originally Posted by Twinny (Post 1355062)
I think it's more of a scripting language. Its limited to graal much like javascript is limited to a web browser.

JavaScript is not limited to a web browser. I have a JavaScript interpreter installed on my system just like a PHP or Ruby interpreter.

xAndrewx 10-28-2007 02:10 PM

Quote:

Originally Posted by Crow (Post 1355056)
O, so you can now compile executables with gscript? I didnt know before, you should teach me how.

Since when has "language" been defined as compiling exe's?

Twinny 10-28-2007 02:55 PM

Quote:

Originally Posted by Skyld (Post 1355064)
JavaScript is not limited to a web browser. I have a JavaScript interpreter installed on my system just like a PHP or Ruby interpreter.

Funky. Its still a scripting language though so what differentiates gscript from javascript?

Crow 10-28-2007 03:09 PM

Quote:

Originally Posted by xAndrewx (Post 1355065)
Since when has "language" been defined as compiling exe's?

Not language, but programming. I interpret "programming" as doing you own stuff.


Quote:

Originally Posted by Twinny (Post 1355072)
Funky. Its still a scripting language though so what differentiates gscript from javascript?

Gscript belongs to a game, Java has more possibilities and lags the **** out of your pc if the code is too complex.

Twinny 10-28-2007 03:19 PM

Quote:

Originally Posted by Crow (Post 1355073)
Gscript belongs to a game, Java has more possibilities and lags the **** out of your pc if the code is too complex.

....Java is not javascript :whatever:

Crow 10-28-2007 03:27 PM

Quote:

Originally Posted by Twinny (Post 1355075)
....Java is not javascript :whatever:

Oh, you are right. I'm always mixing up those two :D

napo_p2p 10-28-2007 07:26 PM

Quote:

Originally Posted by Wikipedia
Scripting languages, also called script languages, are programming languages that are interpreted or compiled each time they run. Scripts are interpreted and executed directly from their source code, which are generally text files containing language specific markup. Thus, "scripts" are often treated as distinct from "programs", which are typically compiled from source code into binary executable files (i.e. machine code) only after changes and do not need to have the source available to function.

I'm fairly sure scripts on Graal are interpreted from the source each time they are run and not compiled, unless Stefan knows something that I don't (which is highly likely :P).

Plus, we'd probably be calling our code 'programs' and not 'scripts' if gscript was a programming language. To top it off, the forum for such 'scripts' is called: NPC scripting.

Crow 10-28-2007 07:37 PM

And its Gscript :f

Admins 10-28-2007 07:53 PM

And it's called C++ script, so what? Please stop those nonsense discussions. Of course Graal scripts are compiled. Java is used for billion dollar transactions, and you don't want to call it a programming language just because it's not compiled into machine code? If you want to say that programming is a higher kind of art than scripting then it's probably to show a difference between a hired programmer and a script kiddie, but scripting languages are still programming languages.

Please stay on-topic (will need to delete those messages anyway I guess).

Crono 10-28-2007 07:56 PM

For a second I thought this thread was about me...

Crow 10-28-2007 07:58 PM

Quote:

Originally Posted by Stefan (Post 1355105)
And it's called C++ script, so what? Please stop those nonsense discussions. Of course Graal scripts are compiled. Java is used for billion dollar transactions, and you don't want to call it a programming language just because it's not compiled into machine code? If you want to say that programming is a higher kind of art than scripting then it's probably to show a difference between a hired programmer and a script kiddie, but scripting languages are still programming languages.

Please stay on-topic (will need to delete those messages anyway I guess).

I didnt say that programming is a "higher kind of art", but I also never heard of "C++ script". Its just "C++". When looking on google for "C++ script" I am just getting some posts in random forums where people ask for help with their "C++ script" :<

Novo 10-28-2007 09:09 PM

Quote:

Originally Posted by Crow (Post 1355107)
I didnt say that programming is a "higher kind of art", but I also never heard of "C++ script". Its just "C++". When looking on google for "C++ script" I am just getting some posts in random forums where people ask for help with their "C++ script" :<

Coding = Programming or Scripting.
Programming = Code that is Compiled into Computer Language (Assembly)
Scripting = Code that is Interpreted by a virtual machine.

Scripting provides better diversity ( running on multiple OS without problems )
Programming provides better speed ( doesn't need to be interpreted )

Both are PRACTICAL and both provide their own uses. In speed-critical apps, programming is the choice... In multi-os, scripting is the choice.

Neither are superior to each other... Especially when computers are pretty fast and libraries are plenty... The difference between them aren't that great. ( Graal is compiled, yet runs on various OSes... And GScript is interpreted, but doesn't have a huge difference in speed than if it were compiled )

Admins 10-28-2007 10:49 PM

Please check out http://en.wikipedia.org/wiki/Scripting_language if you have still confusion about programming languages.


All times are GMT +2. The time now is 10:19 PM.

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