ID:135340
 
I've lived in silence long enough! ;) I'd really like to be able to refer to the members of an object without needing to create a reference variable for it.

Eg.

locate(5,5,1).icon_state = "Blah"

or

for(var/a = 1, a < 11, a++)
myarray[a].dir = EAST


How plausible is it for this to be added?
I've personally always liked the fact that you have to typecast a list member before you can access its properties. That way when you look at the code later, it's easy to figure out what's what.

However I think it might be nice to be able to create lists whose members can only be one predifined type, and access them like in your suggestion.
The main change would be giving each proc a return type, and each list a container type.

There's room in the syntax for that, luckily:

var/list/mob/player/PlayerList = list()


This is valid DM syntax at the moment, but the /mob/player typepath is simply ignored. It shouldn't be too hard in theory to make use of it.

Procs don't currently have a supported syntax for this, but you could do something like this: (The below snippet will currently generate an "invalid proc definition" compilation error.)

mob
proc
obj/item/FindItem()


That would make the proc claim to return the type "/obj/item".

Of course, seeing as BYOND isn't strictly typed, you'd have to be careful using this; if your proc returned a type of object that it claimed not to return, you could get nasty runtime errors when trying to access members of it. (This still applies now, except that it's much easier to check for those conditions when you have to save the return value using a variable first.)

The same caveat applies if it returns null, of course, but that's a problem universal to most languages (except in C++ where you CAN'T return null unless you're returning a pointer, or the compiler allows you to not execute a "return blah" statement before returning... but I digress).

So, yeah, it's probably doable... but don't hold your breath. =P