ID:2144729
 
Code:
mob/var/list/PassiveSkills=list()
obj/Skills
Click()
if(usr.HasPassiveSkill("[src.name]"))
var/Skills/Passive/S=new

//S=usr.PassiveSkills.Find("[src.name]")
//or
//S=usr.PassiveSkills["[src.name]"]

S.Level+=1
world<<"Upgraded [src.name]!"
else
if(!usr.SkillsPoints) return
var/Skills/Passive/NS="/Skills/[src.name]"
NS=new NS
NS.Level=1
usr.PassiveSkills.Add(NS)
world<<"<b>Added new skill - [src.name]"


Problem description:
Hallo, I've got problem with define var. I need Find "skill" obj in user list, and define it to some var.
I have o idea, what i do wrong.


@Edit:

I've find alternative. But is can anyone show me another way?
                for(var/Skills/Passive/P in usr.PassiveSkills)  if("[P.name]"=="[src.name]")
S=P
You could use an associative list, i.e.:

var/skills/passive/p = new
passive_skills[p.id] = p


Then checking for a passive is as simple as:

proc/has_passive(passive_id)
return passive_skills && passive_skills[passive_id]


Food for thought: Something you want to avoid is list initialization when and where you do not need it. Currently you have all mobs setup to have a passive list, when a fraction of them will likely use it.
Can you further explain why one should avoid this? Does it have to do with CPU?
Can you further explain why one should avoid this

Memory usage and CPU.

Initializing a list takes processing time. If you are never going to use that list on an object that has it initialized, you are just wasting that time.

Some tasks in DM (such as manual deletion) require the engine to look through every object in memory and every list index in memory. This means that the fewer objects/lists/datums/turfs/variables/list/positions you have in active memory, the faster manual deletion is.

Manually deleting objects can actually be one of the most intensive things a game can do. It's best to understand garbage collection and plan ahead using C++ style destructors and tracked circular references.

Also, memory. Memory is a precious resource for x86 programs. You have only a limited amount. Although, if your project is running up on 4 gigs of memory, you are likely doing a lot wrong in the first place. Having more lists than you need increases your memory footprint.

Oh, and not to mention that there are a limited number of lists in the world. It's limited to a little over 16 million. That's a lot, but even so you want to stay well below that limit by lazy-initializing your lists.
Great read as always. Thanks for the clarification.