ID:823267
 
(See the best response by Pirion.)
var/list/list[2]
mob/person
mob/person2

mob/verb/friend(mob/M)
while(1)
for(var/mob/person/x in list)
for(var/mob/person2/y in list)
y=M
if(src.loc==locate(5,5,1))
x.loc=locate(6,5,1)
if(src.loc==locate(5,5,1) && x.loc==locate(6,5,1))
y.loc=locate(5,6,1)
sleep(10)


Problem description: I am confused. I still do not understand lists much but this is what I'm trying to do. I want to add a team. If I am at a certain location then the team will teleport nearby to a certain location. But I have a problem with linking the argument mob/M the two people that I have selected to be added the list person and person2.
Best response
Hey Chakra,

Looks like you are a little confused about how lists acutally work, also 'list' is the name of the list() function and the list datum, so id advise not naming a varible list.

So first thing we would do is use a datum for the team. This itself uses a few lists.
/*Our team datum */
var/list/Teams = new() // So we have a list here. This we will say is a list of teams. We need to say its a new list so we can use it.
Team
{
New() //When a new team is created...
{
..()
Teams+= src //Add it to the list of teams
}

var/list/members = new() //Each team holds a list of members, another new list so we can use this one.
var/mob/owner

proc/AddMember(var/mob/newmember)
{
for(var/Team/Ts in Teams) //So we are looping through each item in the teams list here.
{
if(newmember in Ts.members) //If the new member is in another team (We are looking in the Team Member List here)
{
newmember << "Your already in a team. Leave that one first." //Error message.
return FALSE //and send a failed message back to the caller.
}
}
//If you got here your not in a team. Join us!
members += newmember //So adding to a team.
}
}


So after we got the team datum sorted, we can move into the acutal functionallity of the verb.

mob/verb/MoveMyTeamNearMe()
{
var/Team/MyTeam //Setup a varible for storing the current team.
for(var/Team/Ts in Teams) // So looping the team list here again.
{
if(src in Ts.members) //Looking in the members list for if your in the team.
{
MyTeam = Ts //If I am, set my team.
break //and exit the loop.
}
}
if(MyTeam && src.loc==locate(5,5,1)) //If we found a team and are in the certian location
{
for(var/mob/x in MyTeam.members) //Loop through each of the team members.
{
if(x == src) continue // If it is myself...go to the next person instead.
x.loc = locate(6,6,1) //Locate each at the specified location.
}
}
else
{
src << "Either no team, or not at the specified location." //The error if no team or not int the correct place.
}
}


Let me know what questions you have, and look closely how those loops and lists were used together.

Thanks!
In response to Pirion (#1)
Looks like I cannot edit, but this line:

if(newmember in Ts.member)

Should be:
if(newmember in Ts.members)

update: edit worked.
darn it i don't understand this at all. does that coding allow for players 1-3 in team to be at a certain location when an encounter happens?
Yes, it can be used to do that.

What we are doing here is saying rather than the people being this:

var/person/x
var/person/y
var/person/z

They are:
var/list/people[1]
var/list/people[2]
var/list/people[3]

So we can say, for each of the people do an action (as people[1] is a person, its just a list form) and then it lets us do the same action to each if them if we want.

for each in persons
do
action


It would be the equal to saying:

for each of x y and z
do
action
Can you make the coding more simple? Like edit this one:

mob/verb/add_friend2(mob/M)
while(1)
var/mob/o
if(fvar2==1)
M.fvar=2
o.fvar=3
if(src.loc==locate(12,6,1))
if(M.fvar==2)
M.loc=locate(12,3,1)
o.loc=locate(11,9,1)
sleep(10)
Looks like I did it. After many hours of trying to make a team of 3 I did it. This is the coding:

mob/verb/add_friend2(mob/M)
while(1)
if(fvar2==1)
M.fvar=2
fvar2=2
anothavar=2
else if(fvar2==2 && anothavar==1)
M.fvar=3
if(src.loc==locate(12,6,1) && M.fvar==2)
M.loc=locate(12,3,1)
if(src.loc==locate(12,6,1) && M.fvar==1)
M.loc=locate(11,9,1)
sleep(10)
But you didn't use a list! How many hours will it take to add a forth player to the team? How long will it take to debug that code if something doesn't work as expected?

You're just making more work for yourself! Bite the bullet and learn to use lists, this is the perfect time to do so. :P
I'm trying to learn lists and datums but still not getting them. I couldn't figure how to use a list in this case. I was thinking in submitting encounter system again since I made significant improvements but am insecure that it will be accepted yet. Especially since I don't know how to use lists effectively yet, sir.
Based on the snippet you just posted, I'm guessing your code is still suffering from most of the issues I outlined previously. So I don't think you should resubmit it yet.

Keep working at learning lists. If you're trying to apply them directly to your encounter system, maybe take a step back and just try doing basic experiments with them. Once you figure out how they work, then try to apply them to more specific problems.

As an added bonus, if you do a simple standalone experiment and don't understand the outcome, you can post it in Dev Help and we'll be able to more easily explain what's going on.

Also, no need for the "sir". I'm not that old :<