ID:139828
 
Code:
mob
proc
RandomJutsu()
var/Skills/A=pick(src.Skills)
world<<"[src] used [A]."
A.Activate(src)


Problem description: What I'm trying to do is look in the NPC's skills and randomly pick a skill within the list. It outputs "NPC used Skill" so it's outputting it right but when it comes to activating the skill, I come up with a runtime error: Cannot execute null.Activate(). I can't seem to find what's wrong.. If it's outputting the skill correctly why won't it activate 'that' skill.

Here's the activate proc:

        Activate(mob/User)
if(ismob(User))
if(..())
User.Skill1()

What's inside the mob's Skills list? Where do you add things to it and what do they look like?
You may have told the compiler that is IS a skill, but you cannot fool the game at runtime.

Make sure src.skills only contains objects of the type skill.
Make sure the list isn't an associate list.
Check other common list errors.
In response to Pirion (#2)
Pirion wrote:
You may have told the compiler that is IS a skill, but you cannot fool the game at runtime.

Make sure src.skills only contains objects of the type skill.
Make sure the list isn't an associate list.
Check other common list errors.

Jutsus[0]//the default variable
Jutsus=list(/Skills/Skill1,/Skills/Skill2,/Skills/Skill3)//the npcs variable


I don't thing anything is wrong with the list.
In response to AbdelJN (#3)
Where you call pick(src.Skills), try replacing that with src.Skills[pick(src.Skills)].
Also its good practice to add an istype check to make sure it IS a skill before declaring it one. This will catch any mistakes in the code later without causing any issues that way.
In response to Pirion (#4)
Pirion wrote:
Where you call pick(src.Skills), try replacing that with src.Skills[pick(src.Skills)].

Didn't work. : /

Also its good practice to add an istype check to make sure it IS a skill before declaring it one. This will catch any mistakes in the code later without causing any issues that way.

Yeah I know, I'm going to add the check when I've first got the basic code working.
In response to AbdelJN (#3)
That is a list of type paths. It is not a list of objects. To get an object, you need to use new(). Or, in this case, newlist() may be more convenient.

Note that having a list for every single NPC is going to eat up memory rather quickly, and wastefully if they're all just the same. You should instead work on having a global list that associates mob types with lists of skills.
In response to Garthor (#6)
Garthor wrote:
That is a list of type paths. It is not a list of objects. To get an object, you need to use new(). Or, in this case, newlist() may be more convenient.

Note that having a list for every single NPC is going to eat up memory rather quickly, and wastefully if they're all just the same. You should instead work on having a global list that associates mob types with lists of skills.

Ah thank you, and sounds like a good idea ^.^