Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Using the 'in' operator with multi dimensional arrays (https://forums.graalonline.com/forums/showthread.php?t=134267269)

Vatec 10-18-2012 05:35 AM

Using the 'in' operator with multi dimensional arrays
 
Hi all, I am working on an events system and want to use multi dimensional arrays but that standard "in" operator doesn't work like that, how else would I be able to check if the event name is correct?

PHP Code:

temp.array = {
    {
        
"test""30""30"
    
}, {
        
"event""30""30"
    
}
};
if (
eventName in temp.array) {} 


Starfire2001 10-18-2012 06:04 AM

Quote:

Originally Posted by Vatec (Post 1706010)
Hi all, I am working on an events system and want to use multi dimensional arrays but that standard "in" operator doesn't work like that, how else would I be able to check if the event name is correct?

PHP Code:

temp.array = {
    {
        
"test""30""30"
    
}, {
        
"event""30""30"
    
}
};
if (
eventName in temp.array) {} 


Probably easiest to just maintain a separate array with only event names. Or cycle through the array you have and check against the name against the first param of each.

Vatec 10-18-2012 06:58 AM

Yeah well if there wasn't a simple way to do that then I think it's best to have an array the names, /thread

fowlplay4 10-18-2012 03:34 PM

If you want to keep them in the same array do something like this:

PHP Code:

temp.events = {
  
"event", {3030"otherdata"},
  
"event2", {2020"loldata"}
};

temp.event_name "event";
temp.event_index temp.events.index(temp.event_name);
if (
temp.event_index >= 0) {
  
temp.event_data temp.events[temp.event_index+1];
  
// do stuff


The in operator will also work as well in this case.


All times are GMT +2. The time now is 03:18 AM.

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