Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Array Search (https://forums.graalonline.com/forums/showthread.php?t=87567)

sssssssssss 08-23-2009 05:57 AM

Array Search
 
Ok, nother problem. So out of scripting.
I can't by the slightest remember how to search an array and find out if a var is in it. Example. Have an array of account names and want to do and if account name is in array, then allow.

oo_jazz_oo 08-23-2009 06:02 AM

PHP Code:

if (player.account in this.array)
  
//Your script here 

That?

cbk1994 08-23-2009 06:18 AM

Also remember you can do this for caps-insensitive searching...

PHP Code:

if (array.index(@ player.account) > (- 1)) {
 
// stuff


array.index(obj) returns the index that the object is located at within the array.

sssssssssss 08-23-2009 06:24 AM

those b them, ty.

WhiteDragon 08-23-2009 08:08 AM

Note that if you're working with a really, really big dataset, it may be faster to use something like a scripted binary search (I think there might be one in the code gallery, if not I could write one).

Pelikano 08-23-2009 10:05 AM

Searching Arrays, like REALLY searching them is possible in PHP, not sure if it works in GS2

sssssssssss 08-23-2009 11:39 AM

Its only going to be 10 accounts max probably, ever.

sssssssssss 08-23-2009 11:47 AM

Another question arises, how do i add to a server array? i know how to set, serverr.whatever = {whatever, whatever} but if I want to add and delete from that, how should I go about it?

Riot 08-23-2009 12:10 PM

Quote:

Originally Posted by sssssssssss (Post 1517828)
Another question arises, how do i add to a server array? i know how to set, serverr.whatever = {whatever, whatever} but if I want to add and delete from that, how should I go about it?

Take a look at: http://graal.net/index.php/Creation/...ject_functions

You'll find these functions which may be of use to you:
obj.add(obj2) - adds an object to an array
obj.delete(index) - deletes the object from an array at the specified index
obj.remove(obj2) - removes the first instance of the specified object from the array
obj.replace(index,obj2) - replace the object at the specified index
obj.insert(index,obj2) - insert the object at the index without replacing other indexes

Deas_Voice 08-23-2009 12:16 PM

Quote:

Originally Posted by Riot (Post 1517831)
Take a look at: http://graal.net/index.php/Creation/...ject_functions

You'll find these functions which may be of use to you:
obj.add(obj2) - adds an object to an array
obj.delete(index) - deletes the object from an array at the specified index
obj.remove(obj2) - removes the first instance of the specified object from the array
obj.replace(index,obj2) - replace the object at the specified index
obj.insert(index,obj2) - insert the object at the index without replacing other indexes

and if u want to know how they work,
go to wiki.graal.us!

Switch 08-23-2009 05:25 PM

Quote:

Originally Posted by Deas_Voice (Post 1517834)
and if u want to know how they work,
go to wiki.graal.us!

He explained how they worked :\

sssssssssss 08-24-2009 09:37 AM

thanks for the site! completely forgot about it.


All times are GMT +2. The time now is 11:47 PM.

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