obj/disguise
var/old_icon
verb
wear()
old_icon = usr.icon
usr.icon = icon
remove()
usr.icon = old_icon
Problem description: I'm reading the DM Guide and in chapter 5 it describes storing a something in a var to reuse and the way they wrote the sample code has confused me. could someone elaborate a little more on how this saves the old icon as a var and assigns the new without overwriting the old?
old_icon is a variable. It's declared under the /obj/disguise type, so all instances of that type have their own old_icon variable, similar to how different players can have different names.
After the disguise is worn, it contains the icon that the user had before wearing it.
usr.icon is a variable.
When the disguise is worn, it is assigned to the icon of the disguise itself.
When the disguise is removed (after having been worn), it is assigned to the value of old_icon: the icon that the user had before wearing it.
When old_icon is set to usr.icon, setting usr.icon does not affect the value contained by old_icon, because why would it?