Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-25-2006, 05:46 PM
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
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.
Reply With Quote
  #2  
Old 09-25-2006, 05:49 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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"" ?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #3  
Old 09-25-2006, 10:33 PM
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
Yes
Reply With Quote
  #4  
Old 09-26-2006, 12:56 AM
Rapidwolve Rapidwolve is offline
Registered User
Join Date: Jul 2006
Posts: 1,241
Rapidwolve is an unknown quantity at this point
"Nifty"

o_o wtf
Reply With Quote
  #5  
Old 09-26-2006, 08:33 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Very cool =D
__________________
Reply With Quote
  #6  
Old 09-26-2006, 01:37 PM
contiga contiga is offline
Graal2001 Administration
contiga's Avatar
Join Date: Jul 2004
Location: Netherlands
Posts: 419
contiga is an unknown quantity at this point
Send a message via ICQ to contiga Send a message via AIM to contiga Send a message via MSN to contiga Send a message via Yahoo to contiga
Quote:
Originally Posted by Stefan View Post
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!
__________________
AIM: Contiga122
MSN: [email protected]
Status:
Quote:
Originally Posted by unixmad View Post
I am also awake 3AM to help correct problems.
Quote:
Originally Posted by Bomy Island RC people
Daniel: HoudiniMan is a bad guy =p
*Bell: rofl. I first read that as houdini is a bad man. like the little kid that wants his mommy to keep her away from that boogie man
Daniel: xD
*Rufus: I wouldn't want my kids around him.
Reply With Quote
  #7  
Old 10-06-2006, 10:46 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
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".
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #8  
Old 10-14-2006, 02:43 PM
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
Right now not
Reply With Quote
  #9  
Old 10-14-2006, 08:16 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
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.
Reply With Quote
  #10  
Old 10-18-2006, 05:16 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by jake13jake View Post
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);

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #11  
Old 10-18-2006, 05:24 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 jake13jake View Post
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.
Reply With Quote
  #12  
Old 10-18-2006, 05:31 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Quote:
Originally Posted by jake13jake View Post
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.
Reply With Quote
  #13  
Old 10-18-2006, 11:55 PM
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
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.
Reply With Quote
  #14  
Old 10-20-2006, 04:55 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by Skyld View Post
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.
Reply With Quote
  #15  
Old 10-20-2006, 09:13 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
Quote:
Originally Posted by jake13jake View Post
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.
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 09:52 PM.


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