ID:868265
 
Keywords: error, src, undefined, usr, var
(See the best response by LordAndrew.)
Code:
mob
player
icon='player.dmi'
icon_state="suit"
var
cNavSkill = 55//navigator skill on scale 01-100

proc
checkNav()
//generate random placement errors
var/navErrorX = rand (1,100)
var/navErrorY = rand (1,100)

//adjust x-dir error by cNavSkill
navErrorX -= src.cNavSkill
navErrorY -= src.cNavSkill


Problem description:
I get a "src.cNavSkill: undefined var" on both lines where it's called in the proc. It happens regardless of whether I use "usr.cNavSkill" or "src.cNavSkill" to call the variable in the proc. I've been reading a lot lately on how I should normally be using "src" instead of "usr" to call variables, and it was while I was changing variable definitions around that I got this error.

I only want this variable assigned to "player" type mobs. It must be an obvious thing, but I sure can't seem to figure it out. I guess I don't understand variables well enough yet.
Based on the tabbing, you've made checkNav() a global procedure. Just tab it under /mob/player like you have for the variable declaration and it'll work.
That appears to have worked, Lord Andrew.

So is there a way for me to call a player.var to a global proc?
In response to OrionBPG
Best response
Indeed. Simply allow the global procedure to accept an argument (in this case you'd want it to accept a /mob/player.)

mob
player
var
chocolateDonuts = 0

Login()
..()

giveDonuts(src, 10)

src << "You have [chocolateDonuts] chocolate donuts!"

proc
giveDonuts(mob/player/m, amount)
// If for instance we tried to supply something that wasn't a /mob/player, just return the procedure and do nothing.
if(!istype(m)) return

m.chocolateDonuts += amount
proc/stuff()
src<<"Hi!"

This makes the world see the text. "Hi!". So no one else can see it. Basically, src is the world. If you say src.cNavSkill, that's the world's var, which doesn't exist.

Now if you put it somewhere else:
var/cNavSkill

You would get no errors, but nothing would happen to the player, because the variable is assigned to the world.
Ahh. Ok, now I get it.

Thanks to both of you for the education. I have a better feel for variable scoping now. Looks like my variable tree will need some re-arranging.