ID:264645
 
Code:
    if(findtext(src.key,Admins))
src<<"You are an Admin"
else
src<<"Haha you arnt admin"


Problem description: Well i added me and a friend to this list and tryed with another friend to test if it works but this code gives everyone Admin. Any idea? =P

When you're looking for something in a list, you implore Find(), usually formatted as such:

if(admin.Find(key)) src << "You're an administrator, it seems."
else src << "Normalcy for you!"
1) when doing something and you don't know what you're doing, read the documentation.
2) when you're using functions you don't know what do, read the documentation.
3) read the documentation.

BYOND has two things for you to use. One, the guide located on the developer main page. This guide will teach you how to use the basic object structures and how it functions in general. Two, the reference, located on the developer main page AND accessible through the F1 key in Dream Maker (or you can go to Help -> Reference). In this reference, there is reference material for pretty much every variable, function, and object type you might want to use.

In this case, you might want to look up what lists are, what findtext does, and you might soon see why findtext does not work with lists (hint: it finds text in another text string, not another list). While looking at the "list" entry in the reference, you will find a list of functions (also called procs). One of which is called "Find." Using the Find() function (which belongs to your list), you can find any object, type path, number, string, or anything that currently exists in your list (if it does).

var/list/fruits = new
fruits += "apple"
fruits += "oranges"

var/list/vegetables = new
vegetables += "celery"
vegetables += "broccoli"

if (fruits.Find("apple"))
world << "All is right with the world."
else
world << "Houston, we have a problem."


In this example, we create a list of fruits and vegetables and then fill it with the text names of fruits and vegetables. fruits.Find("apple") will look for the text string "apple" within the contents of the list. If it is found, it will return its position in the list. The short version is, if "apple" is found in the list, the if() block will execute. Otherwise, the else block will execute.

Alternatively, you can use the "in" operator which returns a normal TRUE or FALSE (at least here it does).
if ("apple" in fruits)
// etc...
else
// etc...


Have a great day.
Ok, the findtext() proc is to find text from a string, not a list. Find() proc for lists and in list() are different.

Example of findtext() proc
mob/Login()
if(findtext(src.key,"a"))
src<<"Found an 'a' in '[src.key]'"
else
src<<"'A' wasn't found in '[src.key]'"

Example of Find() proc for lists
var/list/stuff=list("potatoes","apples")
mob/Login()
if(stuff.Find("potatoes"))
src<<"potatoes was found in the list 'stuff'"
else
src<<"potatoes doesn't exist in the list 'stuff'"

Example of in list()
var/list/stuff=list("potatoes","apples")
mob/Login()
if("potatoes" in stuff)
src<<"potatoes was found in the list 'stuff'"
else
src<<"potatoes doesn't exist in the list 'stuff'"
//also another method
mob/Login()
if("potatoes" in list("potatoes","apples"))
src<<"potatoes was found in the list"
else
src<<"potatoes doesn't exist in the list"

I hope that helped.