mob
var
feats = new/list(5)
if (src.feats() == "Ambidexterity")
ID:146990
![]() Nov 18 2004, 11:48 am
|
|
Ive been coding for awhile but I still cant seem to make a list work Ive read the help file and the blue book but I cant figure out what to do could someone tell me what Im doing wrong.
mob var if (src.feats() == "Ambidexterity") |
![]() Nov 18 2004, 12:47 pm
|
|
I think I know what you're trying to do, but next time (or this time if my solution isn't working), please post more information so that you can be helped. Anyway,
mob/var/list/feats=new() Then, if you're looking for something named "Ambidexterity" in feats, you would do the following: feats.Find("Ambidexterity")
Or, in your case, if(feats.Find("Ambidexterity") Of course, if you were looking for an object in mob/var/list/feats, then you would do something like this: if(feats.Find(/obj/Ambidexterity/)
Next time, please remember to include more information, because it's difficult to try to figure out what you're trying to do when you don't tell us. |
Zaltron, there are multiple things wrong with that. Please think before giving out advice. First of all,
mob/var/list/feats=list()//creates the list of feats is not true. That doesn't create the list, but merely defines it, and doesn't create it. Therefore, when you try adding "Ambidexterity to feats, it will give you a runtime error stating that it can't modify a null list. Basically, if lists were plastic bags, then you would be describing the plastic bag. Having knowledge of what a plastic bag is, and having a plastic bag, however are two very different things. Your coding would know what feats(The metaphorical plastic bag) is, but it wouldn't have one. What you're trying to do in your coding, is to add "Ambidexterity" to a non-existant bag, as opposed to an empty one, which would be created using: mob/var/list/feats=new() The above line of code would both create AND define the bag. |
Before saying that i'm wrong test it with Dream Maker. list() is a proc in which creates the list. The code I posted on my previous post works fine and will not give you runtime errors.
|
To add onto what you just said, list() creates and returns a new list containing any elements you pass into it, meaning it will simply create a new, empty list if you don't pass anything into it as you did. Thus setting something to list() will result in the variable referencing a new list list as using the new statement would and is a reasonable way to do this. In fact, I use list instead of new as well.
I tend to avoid calling list() a function though as, oddly, it works at compile time where other functions do not (understandably). That is beside the point, though is worth knowing. |