ID:175207
 
Is there a way to do something like the following: (assume that myArray is an array of type mob)

world << myArray[1].name

without doing something like this:

var mob/thisChar = myArray[1]
world << thisChar.name




I'm not totally sure, but something like this might work.

var
list
mob/array = list()


That should allow you to access mob variables for use within the list, but again, I'm not sure, and have never actually tested.
In response to Nadrew
I would have defined it as:
var/mob/myArray[]
In response to CableMonkey
After some testing, I've found you can't use the . operation after the [] operation, not sure of any workarounds off hand, but I don't know if it's even possible.
Ex:

mob
verb
Test()
var/mob/people[1]
people[1] = new/mob()
people[1].name = "Bob"
world << people[1].name


Errors:
loading test.dme
test.dm:6:error: .: expected end of statement
test.dm:7:error: .: expected end of statement

test.dmb - 2 errors, 0 warnings (double-click on an error to jump to it)


The parser doesn't like this at all.
In response to Nadrew
In Java, you can (and completely optional) put parenthesis around the array and then put the variable/method name outside of that...like:

<code>System.out.println((myArray[1]).name);</ code>

...but not in DM.
CableMonkey wrote:
Is there a way to do something like the following: (assume that myArray is an array of type mob)

world << myArray[1].name

without doing something like this:

var mob/thisChar = myArray[1]
> world << thisChar.name


As discussed, you can't do this, though it would be a nice addition to the language.
In response to Deadron
Maybe it should be a feature request!
In response to Deadron
Deadron wrote:
CableMonkey wrote:
Is there a way to do something like the following: (assume that myArray is an array of type mob)
world << myArray[1].name
without doing something like this:
var mob/thisChar = myArray[1]
world << thisChar.name
As discussed, you can't do this, though it would be a nice addition to the language.

If this is doable, I think it will only be via the : operator. Since BYOND's lists aren't typed, it wouldn't know in advance whether myArray[1] is an atom or a mob or a number or a string. With : you could at least fudge it, and it'd put a little more use into the operator.

Of course I suspect that would screw up the original Scream of the Stickster code, which uses the ?: construction in a couple of places and applies any tricks it can to avoid using parentheses in there. In DM the : operator makes ?: a little tricky to use.

[EDIT]
Far more useful would be some kind of return type operator for procs, perhaps a modified as clause that would say "as mob/player" or some such. Then you could use . and : after parentheses with some code, and that I'm certain would screw up something else--but it'd be worth it.

Lummox JR