ID:116263
 
Well, as of late I've been making posts on things I've been randomly figuring out on BYOND. Well, I got a new one.


I'm sure if you've been programing for awhile, you've run across a situation were you needed to assign an atom's variable to another atom. Which, as I've always done it, would turn out like this.

mob/var/sword=new/obj/weapons/sword


This is fine and dandy until you want to access variables within this variable. Now, you could COMPLETELY trust your programming and do it the non-advised src.sword:sharpness way. Notice the : . Or you could even do it the safe var/obj/weapons/sword/SWORD = src.sword;if(istype(SWORD,/obj/weapons/ sword/)){SWORD.name="sword"}

Or, you could make the variable STRICTLY for obj/weapons/sword path... Like so.

mob/var/obj/weapons/sword=new/obj/weapons/sword

mob/verb/Change_Sword_Sharpness(N as num)
if(src.sword)
src.sword.sharpness=N

obj/weapons
sword
var/sharpness=4
bow
staff


Now, granted. This way will still require a path check(the if I used). However, I can't help but feel as though this method might prove to help save a line of code here and there :p...
You've been here since '03 and you just now figured this out?
I focus on other things like imcompentense :p.... Leave me be!
Incompetence*
I'd name the variable "weapon" rather than "sword" so you don't get confused by thinking the variable is of /obj/weapons/sword (which would be mob/var/obj/weapons/sword/sword) rather than /obj/weapons.

I think it pretty much stems from the whole "typecasting" concept.
Kaiocho, it was more or less an example on paths playing an effect on variables. Also, typecasting >.<?