ID:263726
 
Code:
mob
player
var
target=null
icon='player.dmi'
icon_state="human"
Login()
world<<"[usr] has entered the universe"
..()





client/Click(mob/O)
//if what they clicked is a mob
if(istype(O,/mob/))
//if they clicked themselves
if(O == usr)
world<<"Coo coo cachu!"
//Otherwise, set the mob to the persons target
else
world<<"Moo!"
O.overlays += image('target.dmi')
usr.target=O.type
//if they clicked an object, let them know. And target it.
if(istype(O,/obj/))
world<<"LOL!"
O.overlays += image('target.dmi', icon_state="object")
usr.target=O.type


Problem description:
It claims that target is an undefined variable.
What am I doing wrong?

Since you're using Click() under client, you'll need to access the client's mob var. In order to to do that, you need to do usr.mob.target.
In response to Kalzar
Kalzar wrote:
Since you're using Click() under client, you'll need to access the client's mob var. In order to to do that, you need to do usr.mob.target.

At least get the reason right, and that still wouldn't help:

"usr" (and, most likely "mob") is a /mob, "target" is defined under /mob/player, so variables of just /mob cannot access it.

The best way is a combination like this at the beginning:
if(istype(mob, /mob/player))
var/mob/player/player = mob


then you would use "player" instead of "usr".

As a side note, usr isn't a good choice in the client/Click() proc, even though it should be valid, it should always be the same as mob.
In response to Kalzar
Kalzar wrote:
Since you're using Click() under client, you'll need to access the client's mob var. In order to to do that, you need to do usr.mob.target.

Way off, actually. usr.mob doesn't exist because usr is already a mob. What you probably meant was usr.client.mob, or just mob, but really usr == mob in a client verb.

The problem is, target is defined under /mob/player, not under /mob itself, but usr is only known to be a /mob type. Solution: Define target for all mobs, not just players.

Lummox JR
In response to Lummox JR
Haha. Err. Yeah. I was going to play the drunk card and try and get off with that, but no excuse.

Probably should have double checked what I was saying.

I swear, school is sapping my brain.
In response to Kalzar
YOU FOOL!
In response to The Naked Ninja
Well jeebus, that was simple. I should start keeping my code in the same .dm files, rather than different files for each little thing(I keep weapons, battle handline, targeting, spells, items, login/logout, turf and area in their own files).

At least I don't feel as stupid as when I tried to use '=' instead of ':' in CSS.

Geeze, did I feel like an idiot.