Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   checking an array's contents (https://forums.graalonline.com/forums/showthread.php?t=134264574)

oralgnome 09-17-2011 05:03 AM

checking an array's contents
 
I wonder if there's a way to just check an array's contents without actually doing so, for instance if I had an array full of account strings how would I check if one of them was the client's player.account? account.array[someselectingparams] (what would those params be?)

scriptless 09-17-2011 05:24 AM

This is an example of an array:
PHP Code:

temp.array = {"hello","world"};
player.chat temp.array[0]; // 0 is our index 

Output:
PHP Code:

hello 

Using an index of 1 would result in:
PHP Code:

world 

If you just want to see if a player's account name is in the array you can use:
PHP Code:

if ( player.account in temp.array ) {
  
// do stuff



oralgnome 09-17-2011 05:53 AM

I'm not a n00b, I know what an array and index is (I wrote in the post) I was just merely asking if there was a way to check the array content (because in java normally you'd loop through each value). Thanks for the reply though helped me solve my problem - can't imagine why there is an 'in' operator though lol gs2

scriptless 09-17-2011 06:26 AM

Quote:

Originally Posted by oralgnome (Post 1668401)
I'm not a n00b, I know what an array and index is (I wrote in the post) I was just merely asking if there was a way to check the array content (because in java normally you'd loop through each value). Thanks for the reply though helped me solve my problem - can't imagine why there is an 'in' operator though lol gs2

Sorry, wasn't trying to imply you were a noob. Just informing fellow passer-by's that may happen to stumble upon this thread.

Yeah, "in" can make things so much easier.

gaben 09-24-2011 04:27 PM

i was wondering as well if you can check if a value is not in array with a similar method

Crow 09-24-2011 04:31 PM

Quote:

Originally Posted by gaben (Post 1669000)
i was wondering as well if you can check if a value is not in array with a similar method

PHP Code:

if (!(temp.element in temp.array)) 



All times are GMT +2. The time now is 11:01 AM.

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