Parenthesis - Parenthesis
squared things - Brackets
squiggly things - Braces
I don't know what is correct but just throwing this out there so that maybe terminology can be standardized, I have seen "experts" who teach classes refer to Braces (squiggly things) as "squiggly things" or "squiggly parenthesis".
The above was just filler because I actually have a real tip buried in here for those not in the know which until last night, I was one of them til I did a minor bit of testing.
On to the Tip!
So for millennia I have been wanting an easy way to get the position of an element within an array without having to 'for' through the array (okay not millennia but months). Last night while writing a method for a religion system, a light bulb turned on in my head and I thought "let me try a simple check to see if x was in array" and see what that returns, if it returned simply "true" (1 in our case), then I would bug Turley for a feature request so let's take a look at a simple dot command I wrote and I will tell you what the outcome was.
Code: Select all
use uo;
use os;
program test_array( mobile, text )
var my_array := Array{ 1, 2, 3, 4, 5, 20 };
var in_array := CInt( text ) in my_array;
SendSysMessage( mobile, ""+in_array, 0x3, 0x42 );
return 1;
endprogram
So I declare my array and in another variable 'in_array' I have that equal 'CInt( text ) in my_array', then I use SendSysMessage to output the result.
The result was, either false (0 for escript) if the number was not found within the array OR if the number was in the array, I am so excited, it is the small things really, the result was the position within the array the value was found!
So to make a long-winded, drawn out post a little bit longer but with a summary so worth skipping to this point:
IF you need to find the position something may be within an array, using something like:
Code: Select all
var in_array := "Fred" in array_of_names;