ID:781220
 
(See the best response by Albro1.)
Is there a way to make a list that contains movable atoms?

I made a new list under a specific object, and I wanted it to have a list called occupants that accounted for any movable atom that crosses it. After making the list I used the atom/O ref with
occupants[]

as such occupants.add(O)
and while it compiles, I get a runtime error after stepping onto the object associated with adding to the list
Best response
Why do you need this list? You can just check the bounds.

for(var/atom/a in bounds())
if(a == src)
continue
// do whatever here


You can also check an atom's locs.
for(var/atom/a in locs)
// do whatever


The above is assuming you are using pixel movement. If not, then it is even simpler. Just check the loc, because that's a list of things that are over it. Seeing as you are trying to use this list with an object, you just need to check the object's loc's contents for anything other than the object.
for(var/atom/a in loc)
if(a == src)
continue
// do stuff here
You can also use the Enter() and Entered() procedures to handle what is done to a mob that enters a tile.
In response to Deathguard
Deathguard wrote:
You can also use the Enter() and Entered() procedures to handle what is done to a mob that enters a tile.

Don't forget Cross() and Crossed() for pixel movement. Enter() isn't called until the bottom left corner goes into the tile.
The bounds is perfect for what I'm trying to do. Thanks
Is there still a way to make a list of movable atoms?
In response to Raruno
Raruno wrote:
Is there still a way to make a list of movable atoms?

The same way you'd make a list of anything else. Lists don't restrict what can go in them.
I get a runtime error when a movable atoms is added to a list.
so for some reason if I did this it wouldn't work:
mob
entities[]
mob
verb
add_entity(atom/movable/O in view())
entities.Add(O)

Note this is not my actual code but the idea I'm trying to implement
In response to Raruno
Raruno wrote:
I get a runtime error when a movable atoms is added to a list.
so for some reason if I did this it wouldn't work:
> mob
> entities[]
> mob
> verb
> add_entity(atom/movable/O in view())
> entities.Add(O)
>

Note this is not my actual code but the idea I'm trying to implement

mob/var/list/entities = list()
mob/verb/add_entity(atom/movable/O in view())
entities.Add(O)
In response to Raruno
You have to initialize the list first. What you do with "var/L[]" is declare a variable and tell Dream Maker that the variable is a list. This is exactly the same as typing "var/list/L".

What you need is to initialize the list object.
var L[0]

The number in the brackets determines the initial size of the list, filling it with nulls, but usually you're going to want to just make an empty one to start with.