ID:162400
 
I want to create a verb that cheacks my players density and if it is 1 changes the players icon state to a bat and sets their density at 0 , if the players density is 0 ie they are already in bat form it reverts them to their original icon and sets density back to 1.

I have got the verb sorted to check density and convert to bat and i can get it to check the players density and set it back to 1 but how do I get it to restore the original player icon? I assume i need to get it to store it somehow and then revert back?
It's simple. First, store the respective variable (in this case icon) into a backup variable, then use that to restore the variable back to it's previous value afterwards. Unrelated example:
mob/verb/jump()
var/old_density = src.density
src.density = 0
step(src,src.dir)
src.density = old_density


You can also use the initial() proc, however note the difference between the two methods (look initial() up).
Well something like this should work:
mob
verb
change(mob/M)
if(M.density)
M.icon='bat.dmi'
M.density=0
else
M.icon='player.dmi'
M.density=1

Not sure if the mob/M is even needed. If not, use src.
In response to Kaioken
I have tried what you suggested but it doesn't work, my icon stays as a bat. I have put the code below so that maybe you can see where I am going wrong

            Transform_to_Bat()
set category = "Powers" //this code sets the verb to appear in another panel called Powers
if(usr.power<=0)
usr << "You don't have enough power to do this"
else
var/old_icon = src.icon_state
if(usr.density == 1)
usr.icon_state = "bat"
usr.density = 0

else
usr.icon_state = old_icon
usr.density = 1
usr.power -= 10
In response to DisturbedSixx
I don't think this will work because in my game you can choose a number of characteristics at login that then determine you icon state so each player will have a different icon state. I need something that will store an indiviual players state and then restore it.
In response to Sorcha
Well you'd have to use a bunch of if statements to get the right icon_state back.
In response to Sorcha
That's almost correct, however, the old_icon variable has to be declared as /mob/var, or it isn't saved between separate calls of the proc. Also, the line old_icon = icon_state must be inside the first if() before you change icon_state to "bat".

mob
var/old_icon
verb/transform()
if(density)
old_icon = icon_state
icon_state = "bat"
density = 0
else
icon_state = old_icon
density = 1


If the old icon_state is only changed once (in your character creation), then you can also just set it there and not have the old_icon = icon_state line at all in the bat verb.
In response to Garthor
            Transform_to_Bat()
set category = "Powers" //this code sets the verb to appear in another panel called Powers
var/old_icon = icon_state
if(usr.density == 1)
icon_state = "bat"
density = 0
else
icon_state = old_icon
density = 1
power -= 10


I tried what you said using the code above but it doesn't work. When i press the button a second time ie to revert from bat form, my icon remains as a bat. Where am i going wrong?
In response to Sorcha
It'll work but I think what you mean is revert to the previous
character with overlays like hair, clothing etc.
I think you can use the flick() proc but I'm pretty new
to BYOND and am not too sure.
In response to Draganath
Not even close.

The issue is that you didn't follow the advice I wrote.
In response to DisturbedSixx
..Or a variable. Ever heard of them?