ID:2372842
 
Code:
world/New()
var/i
for(i=1, i<=5, i++)
var/mob/P = new/mob
P.AssignSex()
P.AssignFirstName()
P.AssignLastName()
ListOfMobs[i] = P
var
ListOfMobs[5]

mob
verb
Refresh()
world.Reboot()

View_People()
var/i
for(i = 1, i <= ListOfMobs.len, i++)
usr << "The current people in the world are: "
usr << ListOfMobs[i]


Problem description:
So I want to create 5 new mobs when the world starts, give them names, and display those five mobs to the player when they hit the verb.

When I run the game, however, it just says:
The current people in the world are:
mob
mob
mob
mob
mob
[usr.FirstName] [usr.LastName]
Sorry, that's not quite right. This is what I have:

world/New()
var/i
for(i=1, i<=5, i++)
var/mob/P = new/mob
P.AssignSex()
P.AssignFirstName()
P.AssignLastName()
ListOfMobs[i] = P
var
ListOfMobs[5]
mob
verb
Refresh()
world.Reboot()

View_People()
var/i
usr << "The current people in the world are: "
for(i = 1, i <= ListOfMobs.len, i++)
usr << ListOfMobs[i]
Login()
usr.AssignSex()
usr.AssignFirstName()
usr.AssignLastName()
usr << "Your name is " + usr.FirstName + " " + usr.LastName + "."
usr << "You are a " + usr.Sex + "."
usr.name = "[usr.FirstName] [usr.LastName]"
ListOfMobs += usr
You should be using src in Login(), while usr is technically safe there it's not a good habit to get into using usr outside of verbs.

Read Dream Tutor: usr unfriendly for more details there.

Next, it's obvious you're coming from another language due to the syntax you're using, which is usually valid here in most cases but the language does provide easier ways of doing what you're after.

You can embed variables in strings using [].

src << "Your name is [FirstName] [LastName]."


You can loop over lists without having to use long-form for() loops.

for(var/mob/M in ListOfMobs)
src << M.name


Lastly, you're using your list two different ways, both are going to work but might lead to issues down the road, for instance if a mob existed in the list before your loop, you'd end up replacing that first mob. You can use += there as well, since you don't REALLY need to set it to a specific index.

Your list itself should only be given a set number of indices if you know that's the most that list is ever going to have, while it does save some reallocation overhead it does have some overhead of just holding those elements so it comes down to what you need, if you just need a list with 5 elements, defining it that way is perfect and you won't really need to be reallocating things anyways.

However, for a list like the players that are online you'd likely want it to be more flexible.
var/list/ListOfMobs = list()


Will create a list that allocates space as needed.

And finally, to see why the name of the mobs isn't be set, we'd need to see your AssignFirstName() and AssignLastName() procs, but from the looks of it, you're never setting P.name to anything, which could be done in the procs or right afterwards like you do to the player mob in Login().