Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-28-2009, 04:14 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Multi-Dimensional Arrays

It would be great if there was a way to get all index out of a multi-dimensional array. I don't really know how to word this ...

For example,

PHP Code:
temp.staff = {
                    {
"cbk1994""Scripter"},
                    {
"PepperTheCat""Management"}
                  };

temp.staffIndex staff.getIndexes[0].index(@ player.account);
if (
staffIndex > -1) {
  
temp.position staff[staffIndex[1]];
  
player.chat "You are staff:" SPC position;

Instead, something like this has to be used:

PHP Code:
temp.staff = {
                    {
"cbk1994""Scripter"},
                    {
"PepperTheCat""Management"}
                  };

temp.staffIndex null;

for (
temp.member staff) {
  if (
member[0] == player.account) {
    
staffIndex staff.index(@ member);
  }
}

if (
staffIndex > -1) {
  
temp.position staff[staffIndex[1]];
  
player.chat "You are staff:" SPC position;

I thought there was a way to do this, but Skyld didn't know of one, and neither did any of the other people I asked.
__________________
Reply With Quote
  #2  
Old 01-28-2009, 04:37 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Not entirely sure, but just a note, it would probably make more sense to use a hash (TStaticVar/TGraalVar) in this case:

PHP Code:
temp.staff = new TStaticVar();
temp.staff.cbk1994 "Scripter";
temp.staff.PepperTheCat "Management";

temp.playerPosition temp.staff.(@ player.account);
if (
temp.playerPosition != null)
  
player.chat "You are staff:" SPC temp.playerPosition
Reply With Quote
  #3  
Old 01-28-2009, 05:59 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by WhiteDragon View Post
Not entirely sure, but just a note, it would probably make more sense to use a hash (TStaticVar/TGraalVar) in this case:

PHP Code:
temp.staff = new TStaticVar();
temp.staff.cbk1994 "Scripter";
temp.staff.PepperTheCat "Management";

temp.playerPosition temp.staff.(@ player.account);
if (
temp.playerPosition != null)
  
player.chat "You are staff:" SPC temp.playerPosition
Agreed, though there are still cases where this might be needed.
__________________
Reply With Quote
  #4  
Old 01-28-2009, 10:03 AM
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
Typically in languages like PHP, an associative array would be used for this purpose ($staff["Skyld"] = "Global Scripting Admin";) except GScript does not sport this functionality. About the best I can suggest is to use a TStaticVar-esque table like WhiteDragon suggested, since it's about the closest to an associative array as you'll get in GScript.
Reply With Quote
  #5  
Old 01-28-2009, 10:48 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
I expect that a hash table is used for storing the variables of an object, so a TStaticVar is a good choice in that situation.

As I was typing that I just had an idea about associative arrays. I think that in the case of an object, 'a["b"]' would map to 'a.b'. This would allow people to use a more appropriate syntax so it is obvious the coder is using the object as an associative array. In the case where b is a number, it would map to 'a.index<b>' (without brackets).

Example:

staff = new TStaticVar();
staff.timeout = 5;
staff["timeout"] = 5; // same as the previous

staff.(@ "lol" @ 3) = "pancake";
staff["lol" @ 3] = "pancake"; // same as the previous, but clearer (imho)

staff[5] = "five";
echo("5: " @ staff.index5); // example of how number is mapped to variable name
__________________
Reply With Quote
  #6  
Old 01-29-2009, 02:13 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
I'm not a really a fan of the syntax you're suggesting Inverness. All subvariables are referenced the same way with all the objects, there is no reason to adopt that syntax simply because a few other languages use it.

Technically an Array is a subtype of a TStaticVar already, although I'm not sure if the engine changes how it handles them (hash, linked list, etc). I'm not sure if you could still access the variables with the subvariable syntax either, but their might be a (undocumented) way to.
Reply With Quote
  #7  
Old 01-29-2009, 02:20 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
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
I made a thread about the same thing last week.

http://forums.graalonline.com/forums...ad.php?t=83824
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #8  
Old 01-29-2009, 06:36 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 WhiteDragon View Post
I'm not a really a fan of the syntax you're suggesting Inverness. All subvariables are referenced the same way with all the objects, there is no reason to adopt that syntax simply because a few other languages use it.

Technically an Array is a subtype of a TStaticVar already, although I'm not sure if the engine changes how it handles them (hash, linked list, etc). I'm not sure if you could still access the variables with the subvariable syntax either, but their might be a (undocumented) way to.
This would apply to objects, not arrays. Technicalities are irrelevant in this case.

The new syntax would show how you intend to use the object. If we did it like this, then I would never have to use the ugly var.(@ "something") because you have a more proper way to mimic dynamic variables.
__________________
Reply With Quote
  #9  
Old 01-30-2009, 01:52 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Inverness View Post
This would apply to objects, not arrays. Technicalities are irrelevant in this case.
I was talking about objects. The second paragraph was just something I was pointing out in addition.


Quote:
Originally Posted by Inverness View Post
The new syntax would show how you intend to use the object.
Quote:
Originally Posted by Inverness View Post
more proper way
You do realize that all of these statements are subjective? They can all be answered by this nifty statement I had in my post:
Quote:
Originally Posted by WhiteDragon
there is no reason to adopt that syntax simply because a few other languages use it.
Reply With Quote
  #10  
Old 01-30-2009, 02:17 AM
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 WhiteDragon View Post
You do realize that all of these statements are subjective? They can all be answered by this nifty statement I had in my post:
Do you have a better syntax recommendation for showing the reader that you intend to use an object as an associative array, one that is an alternative to the current object.(@ "varname")?

Are you complaining about the syntax itself, or the suggestion?
__________________
Reply With Quote
  #11  
Old 01-30-2009, 03:27 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Inverness View Post
Do you have a better syntax recommendation for showing the reader that you intend to use an object as an associative array, one that is an alternative to the current object.(@ "varname")?

Are you complaining about the syntax itself, or the suggestion?
The suggestion. Why should there be an alternate syntax?
An associative array is a mapping of series of keys to their values, which happens to be what a hash does.
The way Graal chooses to handle this is with subvariables. Introducing the alternate syntax would only make things more confusing and suggest that there is actually a difference between the syntaxes when there isn't.
Reply With Quote
  #12  
Old 01-30-2009, 04:01 AM
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 WhiteDragon View Post
Introducing the alternate syntax would only make things more confusing and suggest that there is actually a difference between the syntaxes when there isn't.
This is true, and I would prefer an actual associative array type, but Stefan is busy and I don't expect such a thing considering the lack of updates to Graal.

My suggestion was simply the easiest way to implement an associative array facade, of course I don't expect that to be implemented either.
__________________
Reply With Quote
  #13  
Old 01-30-2009, 04:07 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Inverness View Post
This is true, and I would prefer an actual associative array type
Why? A hash is the most popular way to implement an associative array so we effectively already have them. All it would be is a syntax change.
Reply With Quote
  #14  
Old 01-30-2009, 05:23 AM
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 WhiteDragon View Post
Why? A hash is the most popular way to implement an associative array so we effectively already have them. All it would be is a syntax change.
Yes, I know it's simply a syntax change, but I dislike the whole dynamic variables thing, I think it's just bad form. In any other language you use a hash table for such things. The new syntax would simply be a facade for that, so it would be obvious you're trying to use the object for that purpose.

*shrug* It's not really important, was just a random idea.
__________________
Reply With Quote
  #15  
Old 01-30-2009, 05:33 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Inverness View Post
*shrug* It's not really important, was just a random idea.
Keep you and your ideas off this forum, boy. :P
Reply With Quote
  #16  
Old 01-30-2009, 05:57 AM
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 WhiteDragon View Post
Keep you and your ideas off this forum, boy. :P
Typical democrat, all about free speech until it's someone or something you don't like. Made you look.
__________________
Reply With Quote
  #17  
Old 01-30-2009, 08:18 AM
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
Quote:
Originally Posted by Inverness View Post
Yes, I know it's simply a syntax change, but I dislike the whole dynamic variables thing, I think it's just bad form. In any other language you use a hash table for such things.
Most dynamic languages just do not make a difference between dynamic variables and hash tables, so I do not think this is bad form at all.
Reply With Quote
  #18  
Old 01-30-2009, 09:04 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 Loriel View Post
Most dynamic languages just do not make a difference between dynamic variables and hash tables, so I do not think this is bad form at all.
I know what you mean, it's just the syntax that I've had issues with. I don't know of another language that lets you create variable names inline.
__________________
Reply With Quote
  #19  
Old 01-30-2009, 11:55 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
Quote:
Originally Posted by Inverness View Post
I know what you mean, it's just the syntax that I've had issues with. I don't know of another language that lets you create variable names inline.
Javascript, Lua.
Edit: I am not sure anymore what you are refering to. Lua at least lets you do getfenv(1)[varname] = 42, equivalent to local varname = 42, I think.

Last edited by Loriel; 01-31-2009 at 12:40 AM..
Reply With Quote
  #20  
Old 01-31-2009, 12:39 AM
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 Loriel View Post
Javascript, Lua.
Edit: Obviously only as entries into a table, but that is what we did here, too.
That is different in syntax than doing something like obj.(@ "var").subvar in Graal, I abhor that.
__________________
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 05:02 AM.


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