How do i make it add ALL mobs without distinction.
//list name is L
test5(mob/M in oview(10))
L += M.name
ID:155752
![]() Mar 26 2011, 5:17 pm
|
|
I'm attempting to add all mob's names in view of a player to a list but the only way I can think to do this would force the player to select which mobs to add to the list.
How do i make it add ALL mobs without distinction. //list name is L |
![]() Mar 26 2011, 5:30 pm (Edited on Mar 26 2011, 6:20 pm)
|
|
This should work.
|
There is a bug in this code, though it is somewhat subtle.
oview() defaults to centreing on 'usr'. In a procedure, use of usr is bad practice. The other problem is the use of a global list for return values. A better proc: proc/mobs_in_view(atom/centre) |
> proc/mobs_in_view(atom/centre) I don't really understand this code. What does adom refer to and centre? How do I access the contents of this list i don't even see where its being stored. It being a procedure, is that what makes it not prompt for a mob selection? I modified the code by changing . to something else and accessed it like a normal list but I get a "list index out of bounds" error but I think this is because im trying to access slots in the list that haven't been taken up. so it seems to work but I still don't understand why. Thanks. |
I wrote some of it using a little shorthand. This version is functionally identical and maybe a little clearer:
proc/mobs_in_view(var/atom/centre) The bit in the parentheses is a variable declaration - I'm saying that this procedure takes one argument, of type /atom, named 'centre'. /atom is the base type for everything that can go on the map - so turfs, areas, mobs, and objs. It doesn't prompt for a mob partially because it's a procedure (and therefore not directly user-accessible), and partially because it doesn't ask for it. '.' is a special variable that all procedures have - I probably shouldn't have used it in an example, it's just shorthand. The list is returned using 'return' like procedures as usual. You can use the proc like this: mob/verb/test_mobs_in_view(mob/m in world) That verb lets you pick a mob in the world, calls the procedure on it and stores the returned value in a list named 'names_in_view', and then loops through the list outputting all the names in it. |
Thank you for this and explaining. I did eventually figure out a way to make it run but it's incredibly sloppy compared to yours. Very much appreciated.
Jp wrote: I wrote some of it using a little shorthand. This version is functionally identical and maybe a little clearer: > proc/mobs_in_view(var/atom/centre) The bit in the parentheses is a variable declaration - I'm saying that this procedure takes one argument, of type /atom, named 'centre'. /atom is the base type for everything that can go on the map - so turfs, areas, mobs, and objs. > mob/verb/test_mobs_in_view(mob/m in world) That verb lets you pick a mob in the world, calls the procedure on it and stores the returned value in a list named 'names_in_view', and then loops through the list outputting all the names in it. |