Jump to content

Question on obse arrays


killing11

Recommended Posts

Something like:

 

Let arrayElement := ArrayName["ReferenceID"] 

If ( arrayElement.getdistance < 200 )

	....

Endif

Link to comment
Share on other sites

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 by DrakeTheDragon
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...