Hi,
Can someone point me in the direction of how to properly code the following situation. Preferably in the "right" or "best" practice.
More or less, I want to compare each value from 2 separate arrays, if the value is present in both, do this, if not do that. I have been looking at methods to do this so and have usually ended up with a nested foreach. I haven't found a lot in the scripting tutorials regarding "if in array".
Context: It is for a command script that powers up certain skill-set. Eg. powering up all warrior type skills. At the same time I want it to remove any skills that are not within the array of warrior skills. I could just do a blanket 'set all skills to 0' but that doesn't seem very professional or right to me to have a players skills set to 0 then to 100 straight after. It should just set it to 100, while removing irrelevant skills. The less blue spam on the screen the better.
Any opinions, direction or advice?
Thanks.
Comparing array values
Moderator: POL Developer
Re: Comparing array values
You can do if ( variable in array )
If you use that approach, you just wont know where it is in array_b - just that its there.
Code: Select all
var array_a = array(1, 2, 3, 4, 5, 6, 7);
var array_b = array(6, 7, 8, 9, 10, 11);
foreach value in ( array_a )
if ( value in array_b )
.... do what ever
endif
endforeach
-
- New User
- Posts: 15
- Joined: Mon Jun 30, 2008 9:07 pm
Re: Comparing array values
Thanks a lot!
I figured there would be something like that but I couldn't find it here or through search or the documentation. Hard to find something when you don't know what your looking for. That worked a treat. My other solutions were less then impressive.
I figured there would be something like that but I couldn't find it here or through search or the documentation. Hard to find something when you don't know what your looking for. That worked a treat. My other solutions were less then impressive.
Re: Comparing array values
Better yet.. Turley just put this into the core's code
Log Message:
-----------
Changed: "in" keyword now returns the arrayindex or 0 if no match was found
Re: Comparing array values
your posting reminds me i think i wanted to change it since i started with the core