killing11 Posted April 5, 2011 Share Posted April 5, 2011 How do I access a array element (of type reference) and use it in say a condition like if (arrayElement.getdistance < 200) xxx endif Link to comment Share on other sites More sharing options...
Hickory Posted April 5, 2011 Share Posted April 5, 2011 Something like: Let arrayElement := ArrayName["ReferenceID"] If ( arrayElement.getdistance < 200 ) .... Endif Link to comment Share on other sites More sharing options...
DrakeTheDragon Posted April 5, 2011 Share Posted April 5, 2011 (edited) How do I access a array element (of type reference) and use it in say a condition like if (arrayElement.getdistance < 200) xxx endif It depends on what type of array it is. If it is of type "Array", i.e. has a numerical index, you access elements like "myArray[1]" or "myArray[indexVar]" just like in C.If it is of type "StringMap", i.e. has a literal index, it's like "myArray["oneIndex"]".To access or modify an array's contents you will have to use the "let" and "eval" commands though, for so-called "OBSE expressions", as the traditional commands like "set" don't know the new OBSE datatypes in all cases or just act differently for them.To iterate through an array without knowing its specific indices you can use "ForEach" like array_var itemArray array_var item ... ForEach item <- itemArray ... Loop Inside this loop then "item["key"]" holds the index and "item["value"]" the contents of the current index of the array the iteration is at. Directly accessing the content the way you did it in your example above I'd not advise to do though. It's safer to use a temporary variable for the reference like "let myRef := myArray[myIndex]" and then use it in a condition or whatever like you did "... myRef.getDistance ...". I hope this helps. edit: Seems I was typing too slowly again. Edited April 5, 2011 by DrakeTheDragon Link to comment Share on other sites More sharing options...
killing11 Posted April 5, 2011 Author Share Posted April 5, 2011 Thanks for both of your replies chaps. I understand now Link to comment Share on other sites More sharing options...
Recommended Posts