ID:142868
 
Code:
var/mob/human/list/mobs
for(var/mob/human/M in world)
if ((M.client && M.start))
mobs += M
if(findText("[mobs]", t))
mobs.invisible = 1


Yes, T is defined and all that, the problem is that it's not looking into what the list has or whatever and looking through each "item" the list contains. I want it to work, my understanding of lists is very limited. I suppose that indexes might be the fix? I don't know.

JUGH wrote:
Code:
> var/mob/human/list/mobs
> for(var/mob/human/M in world)
> if ((M.client && M.start))
> mobs += M
> if(findText("[mobs]", t))
> mobs.invisible = 1
>

There are several early problems here, and then it ends with something that is also wrong, but I'm not sure quite what you're after.

When defining lists, you don't use the format var/mob/human/list/mobs --- all lists are defined in the following way: var/list/mobs, and can contain any data type.

Before adding data to a list, you first need to initialize it (otherwise the list is null, and you can't add to a null list). To do this, you can use the new operator or the list() proc:
var/list/mobs = new    // I prefer this
var/list/mobs = list()


The last if() statement boggles me. Since mobs is a /list, "[mobs]" == "/list". Also, lists only have one variable: len. There is no invisibility attribute. For this reason, I assume you're trying to access the individual mobs in the list, and I'm not sure what you're trying to do with them. Perhaps t is a text string containing names of mobs that should be invisible? In this case, you can simply change the logic when you add the mob to the list. Also, keep in mind that the first argument to findText() is the string to be searched, and the second is the value you're searching for. If you're ever unsure of this, you can access a local DM Reference by pressing F1 in DreamMaker. Rewritten logic based on my understanding of your problem may be like so:
var/list/mobs = new
for(var/mob/human/M in world)
if(M.client && M.start)
if(findText(t, M.name))
M.invisible = 1 // I assume you created invisible; it's not a built-in variable
mobs += M


I hope this helps. If you have further questions, feel free to ask.

Hiead
bump?
In response to JUGH (#2)
Please don't bump unless the original post is at least 24 hours old and has gone off the first page. Especially if it's just over 10 minutes old and is still the first listing!

I believe this used to be in the Community Standards, but I'm unable to locate those now. Huh.

Hiead
remplace
var/mob/human/list/mobs


for
mob/var/list/mobs = list()


i cannot help like you DONT tell us wat you want it to do all i got its suppose to make someone invisible
In response to Hiead (#1)
Hiead wrote:
JUGH wrote:
Code:
> > var/mob/human/list/mobs
> > for(var/mob/human/M in world)
> > if ((M.client && M.start))
> > mobs += M
> > if(findText("[mobs]", t))
> > mobs.invisible = 1
> >

There are several early problems here, and then it ends with something that is also wrong, but I'm not sure quite what you're after.

When defining lists, you don't use the format var/mob/human/list/mobs --- all lists are defined in the following way: var/list/mobs, and can contain any data type.

Before adding data to a list, you first need to initialize it (otherwise the list is null, and you can't add to a null list). To do this, you can use the new operator or the list() proc:
var/list/mobs = new    // I prefer this
> var/list/mobs = list()


The last if() statement boggles me. Since mobs is a /list, "[mobs]" == "/list". Also, lists only have one variable: len. There is no invisibility attribute. For this reason, I assume you're trying to access the individual mobs in the list, and I'm not sure what you're trying to do with them. Perhaps t is a text string containing names of mobs that should be invisible? In this case, you can simply change the logic when you add the mob to the list. Also, keep in mind that the first argument to findText() is the string to be searched, and the second is the value you're searching for. If you're ever unsure of this, you can access a local DM Reference by pressing F1 in DreamMaker. Rewritten logic based on my understanding of your problem may be like so:
> var/list/mobs = new
> for(var/mob/human/M in world)
> if(M.client && M.start)
> if(findText(t, M.name))
> M.invisible = 1 // I assume you created invisible; it's not a built-in variable
> mobs += M


I hope this helps. If you have further questions, feel free to ask.

Hiead

Ah, Thank you for your help, it works, but I don't want to be a moron and have to ask for help with lists forever.
I need you to explain one part of your code.
if(findText(t, M.name))
M.invisible = 1 // I assume you created invisible; it's not a built-in variable
mobs += M

You added it to mobs after you used find text?
How does that work?
I'm sorry, I'm not exactly great at explaining what I mean..but how does it work like that?
I thought it would only work if it was like this
mobs+=M
if(findText(t, M.name))
M.invisible = 1

something like that?
In response to JUGH (#5)
JUGH wrote:
> if(findText(t, M.name))
> M.invisible = 1 // I assume you created invisible; it's not a built-in variable
> mobs += M
>

You added it to mobs after you used find text?
How does that work?

The order of statements doesn't matter here; M is a variable that equals the referenced mob for the entire block under the for() statement. That is, any line indented under the for() line will have M equal to the mob in question (unless one of the lines changes that value). Any time I use M, I'm referencing that mob.

If I nested the mobs += M under the if() statement; that is, if I indented it like so:
for(var/mob/human/M in world)
if(M.client && M.start)
if(findText(t, M.name))
M.invisible = 1
mobs += M

It would only add M to mobs if M.name was found in t. Since it's not, M is just added to the list after setting invisible to 1, if necessary. Think of the logic like this:
<pre>create list: mobs for every /mob/human (M) in world: if(M.client AND M.start) set M.invisible = 1 only if M.name is found in t add M to mobs</pre>
As you can see, the if(findText...) line only affects whether or not M.invisible gets set to 1. It has no impact on the statement that follows it.

I thought it would only work if it was like this
> mobs+=M
> if(findText(t, M.name))
> M.invisible = 1
>

This works exactly the same, except that it searches t and sets M.invisible after adding M to the list.

Hiead
In response to Hiead (#6)

I thought it would only work if it was like this
> > mobs+=M
> > if(findText(t, M.name))
> > M.invisible = 1
> >

This works exactly the same, except that it searches t and sets M.invisible after adding M to the list.

Hiead
Then what's the point of adding mobs+=M
In response to JUGH (#7)
mobs+=M is what adds it to the list. If the whole goal of your code is just to set the invisible var, just do that and don't bother with the list, but since you never stated what you wanted and the code you provided used a list, the code I gave used a list.

Hiead