ID:141816
 
Code:
mob
Shinigami_Examiner
// icon = 'Shinigami.dmi'//
// name = "Shinigami Examiner"//
// icon_state = "Shinigami"//
npc = 1
Click()
if(race == "Human")
if(level >= 10)
switch(input("Do you want to be a shinigami?", text) in list ("Yes", "No"))
if("Yes")
faction = "Soul Society"
faction = 1
usr << "<B>You are now a shinigami"
race = "Shinigami"
switch(input("Join a squad ?", text) in list ("Yes", "No"))
if("Yes")
var/P = rand(1,13)
if(P==1)
squad = "First"
if(P==2)
squad = "Second"
if(P==3)
squad = "Third"
if(P==4)
squad = "Fourth"
if(P==5)
squad = "Fifth"
if(P==6)
squad = "Sixth"
if(P==7)
squad = "Seventh"
if(P==8)
squad = "Eigth"
if(P==9)
squad = "Ninth"
if(P==10)
squad = "Tenth"
if(P==11)
squad = "Eleventh"
if(P==12)
squad = "Twevleth"
if(P==13)
squad = "Thirteenth"


Problem description:

I compiled and got this error npc re-initialization of global var
I've even had this error before when trying to program a AI system. If anyone could help it would be highly appreciated.
What line, and what's the error ?

Also, I see room for improvement on that snippet. I'll be glad to show you how to improve it if you tell me the error and the line.
In response to Andre-g1
Andre-g1 wrote:
What line, and what's the error ?

Also, I see room for improvement on that snippet. I'll be glad to show you how to improve it if you tell me the error and the line.

The line is

"npc" and the error is "npc re-initialization of global var"
In response to Rasengan3oo4
You probably have npc defined as

var/npc


instead of

mob/var/npc
In response to Andre-g1
Andre-g1 wrote:
You probably have npc defined as

> var/npc
>

instead of

> 
> mob/var/npc


oh thanks andre it compiled perfect, I appreciate it a lot
In response to Rasengan3oo4
You shouldn't even have an npc var in the first place, it's pretty ridiculous... if you want to check if a mob belongs to a player, you can check its key (and if you want to check if there is a player currently logged into that mob you can check client). If you need a 'harder', object-specific differentiation you could always check by object type (which npc's and players should really generally be childs of different subtypes due to various differences in the vars/procs needed you'll often have), eg:
mob/character
var/HP
player
human
//...
npc
var/mob/target
Bob
shopkeeper
mob/verb/what_am_i()
set src in world
if(istype(src,/mob/character/player))
usr << "[src] is a player!"
else if(istype(src,/mob/character/npc))
usr << "[src] is a NPC!"
else usr << "I dunno what [src] is!"