ID:132944
 
When I program I like to give players their own sub-type of /mob, and as such all of the relevant variables are stored somewhere like /mob/Player... This creates problems because whenever I try to make a client proc that refers to a client.mob.var it doesn't recognize it. I don't particularly want to define another variable for this if I don't have to. (Though as I was typing this I realized I could just create a new var called var/mob/Player/Mob and use that... and then I wouldn't have to worry about setting and resetting the var...

But ANYWAY~ Is it possible to set the type of mob client mob refers to? And if not... could it be? ... Actually, realizing how simple it is to just create another var... Ignore the second half of that. But is it possible currently to change client.mob to recognize other typecasts?
Hmm, there was a topic like this before. Basically, some vars, namely usr and mob for this case, are supposed to hold an object of a particular base type - in this case, /mob. There is no guarantee it will be /mob/player or any specific type (or in the case of usr it might not even be a player mob), so that's why they're simply defined as the base /mob. Technically whenever you treat such an ambiguously-typed mob, you should verify its type with istype() first, though if you've taken measures to ensure players will only ever have a mob of type /mob/player, then you could probably skip that. Maybe a world var could be added that will change those vars' defined type as 'use at your own risk' type thing, but I dunno if that's even possible due to how the compiler works - it would have to look for this var first thing on compile, or maybe it could be a #define flag in the DME or some such.
However, the point for such a suggestion is the hassle in typecasting vars again and again, yes? Then maybe a shortcut #define would be satisfactory?
//put this in your first file
#define playercast(Var,newVar) var/mob/player/newVar = Var
mob/player
var/score
var/muted
//random, _senseless_ examples:

mob/player/verb/ShowScore()
//(you could just use src here)
playercast(usr,P) //this compiles to "var/mob/player/P = usr"
P << P.score

client/verb/world_say(msg as text)
playercast(src.mob,P)
if(!P.muted) world << "[P]: [msg]"

You could name 'playercast()' shorter if you really wanted to save some typing, and maybe even made versions specifically for 'usr' and 'mob', but eh. You might even want to incorporate a type check in there, while you're at it.
AJX wrote:
But ANYWAY~ Is it possible to set the type of mob client mob refers to? And if not... could it be? ... Actually, realizing how simple it is to just create another var... Ignore the second half of that. But is it possible currently to change client.mob to recognize other typecasts?

Nope. The type for usr and client/mob is hard-coded. It would be quite difficult to change this, if it's possible at all. But since a simple type-cast makes this moot, that's what I recommend using.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
AJX wrote:
But ANYWAY~ Is it possible to set the type of mob client mob refers to? And if not... could it be? ... Actually, realizing how simple it is to just create another var... Ignore the second half of that. But is it possible currently to change client.mob to recognize other typecasts?

Nope. The type for usr and client/mob is hard-coded. It would be quite difficult to change this, if it's possible at all. But since a simple type-cast makes this moot, that's what I recommend using.

Lummox JR

Yep. Figured I'd ask anyway.