Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Trick for In-Array Operator (https://forums.graalonline.com/forums/showthread.php?t=68956)

Admins 09-25-2006 05:46 PM

Trick for In-Array Operator
 
You can check if an array is inside another array by converting the array to string first:

PHP Code:

  temp.arr = {{1,2},{3,4},{5,6}};
  echo(
"check1: " @ ((@{1,2}) in temp.arr));
  echo(
"check2: " temp.arr.index(@{3,4})); 

That might be useful for some optimizations.

ApothiX 09-25-2006 05:49 PM

Nifty. Does @{1,2,3} return a string like "1,2,3" ?

What about 2-Dimensional Arrays?
Does @{{1,2,3},{4,5,6},{7,8,9}} return ""1,2,3","4,5,6","7,8,9"" ?

Admins 09-25-2006 10:33 PM

Yes

Rapidwolve 09-26-2006 12:56 AM

"Nifty"

o_o wtf

xAndrewx 09-26-2006 08:33 AM

Very cool =D

contiga 09-26-2006 01:37 PM

Quote:

Originally Posted by Stefan (Post 1222118)
You can check if an array is inside another array by converting the array to string first:

PHP Code:

  temp.arr = {{1,2},{3,4},{5,6}};
  echo(
"check1: " @ ((@{1,2}) in temp.arr));
  echo(
"check2: " temp.arr.index(@{3,4})); 

That might be useful for some optimizations.

Very nice!

xXziroXx 10-06-2006 10:46 PM

Is there a way to check if only a part of an array is in the array? For example, serverr.staff is set like this:


serverr.staff="acc1,rank","acc2,rank"

I want to find out if acc1 is listed in the array, without doing a loop, is it possible?

I tried:

((@{"acc1",}) in serverr.staff)

Wich returned 0, but if I did:

((@{"acc1","rank"}) in serverr.staff)

it returned 1. But like I said, I only want to find out if "acc1" is listed, and not "rank".

Admins 10-14-2006 02:43 PM

Right now not

jake13jake 10-14-2006 08:16 PM

Yea, this would be a good example of where I'd want to use a struct. Stefan, so much of my scripting would be cleaner if you had structs in GS2. Instead I'm stuck using parallel arrays, and ugly use of makevar.

ApothiX 10-18-2006 05:16 PM

Quote:

Originally Posted by jake13jake (Post 1231032)
Yea, this would be a good example of where I'd want to use a struct. Stefan, so much of my scripting would be cleaner if you had structs in GS2. Instead I'm stuck using parallel arrays, and ugly use of makevar.

PHP Code:

function onCreated() {
  
temp.blah = new TStaticVar();
  
temp.blah.var1 "hey";
  
temp.blah.var2 "look";
  
temp.blah.var3 "It's a struct!";
  
CheckStruct(temp.blah);
}

function 
CheckStruct(structvar) {
  echo(
structvar.var3);



Skyld 10-18-2006 05:24 PM

Quote:

Originally Posted by jake13jake (Post 1231032)
Yea, this would be a good example of where I'd want to use a struct. Stefan, so much of my scripting would be cleaner if you had structs in GS2. Instead I'm stuck using parallel arrays, and ugly use of makevar.

You appear to be another one who has difficulty scripting inside the confines of the language.

Twinny 10-18-2006 05:31 PM

Quote:

Originally Posted by jake13jake (Post 1231032)
Instead I'm stuck using parallel arrays, and ugly use of makevar.

Makevar sucks anyways. If you really need any special coding, make it yourself. Everyone else manages using GS2.

Admins 10-18-2006 11:55 PM

For small arrays (<200 members) it is probably not a problem to cycle through it, for bigger arrays it is sometimes necessary to optimize the use of arrays a little bit to use array.index() and similar, in case you have problems with the loop limit.

jake13jake 10-20-2006 04:55 AM

Quote:

Originally Posted by Skyld (Post 1232625)
You appear to be another one who has difficulty scripting inside the confines of the language.

I only say something when the language limits its own potential. I don't really have difficulty scripting within the confines of gscript. Seriously, go investigate for yourself.

I do frown upon you though. Being a global, you're not being very good with PR, and you are in fact coming off as an elitist (tbh, nobody really likes elitists). Encourage others, don't look down on them.

Skyld 10-20-2006 09:13 AM

Quote:

Originally Posted by jake13jake (Post 1233358)
I only say something when the language limits its own potential. I don't really have difficulty scripting within the confines of gscript. Seriously, go investigate for yourself.

I do frown upon you though. Being a global, you're not being very good with PR, and you are in fact coming off as an elitist (tbh, nobody really likes elitists). Encourage others, don't look down on them.

I know you're a competent scripter, but I don't see any point in needing to add structs when you could probably do the job well enough with TStaticVars.

jake13jake 10-21-2006 10:33 PM

Quote:

Originally Posted by Skyld (Post 1233383)
I know you're a competent scripter, but I don't see any point in needing to add structs when you could probably do the job well enough with TStaticVars.

I completely agree with that, but because of what little documentation gs2 has, I was unaware.


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

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