ID:151542
 
I was riding my fourwheeler a few weeks ago, and was thinking about how I could make switching icons simpler. I thought of a simple proc. Is it efficient or not?

mob/proc/IconSwitch(atom/icon1,icon2,state)
icon1.icon = icon2
icon1.icon_state = "[state]"


Practical uses would include:

mob/verb/Switch_Icon()
IconSwitch(usr,'person.dmi',"hi")
There's not really room for being inefficient there, other than that being too simplistic to require a new proc. If you don't plan on expanding that somehow (or using it as a hook, which I doubt you've thought about) and you're really too lazy to type out the 2 lines each time, you could always use a preprocessor macro to cut the amount of typing down.

Also, it seems that you don't really grasp procs yet. It doesn't look like you understand that you made that an object proc (a /mob proc). The only reason your code compiles is because when you don't specify a source for an object proc, Dream Maker checks if the src is valid for it and if so uses that (so the call is really src.IconSwitch() -- in that case src is the same as usr most of the time). You also use an argument to refer to the object when you should just refer to it by being the source of the proc if you're making it an object proc. You should read up on procs.
In response to Kaioken
I will not deny that you are right, I am still new with procs, which is why I have been experimenting with them. If I remove the mob/ from the beginning of the proc(Which is making it a global proc, if I am not mistaken. I know what I mean, just not always the necessary terms to explain it to others), will that solve most of what you are saying there?
In response to Albro1
Albro1 wrote:
If I remove the mob/ from the beginning of the proc, will that solve most of what you are saying there?

I wouldn't remove the "mob/" part, but rather change it to "atom/" and remove the first argument to the proc. Then you can use src in place of icon1.

Your code:
mob/proc/IconSwitch(atom/icon1,icon2,state)
icon1.icon = icon2
icon1.icon_state = "[state]"


A small revision:
atom/proc/IconSwitch(new_icon, new_icon_state)
src.icon = new_icon
src.icon_state = new_icon_state
// note also that I took out the unnecessary string embedding


You would then call it like so:
mob/verb/Switch_Icon()
usr.IconSwitch('foo.dmi', "bar")
In response to Kuraudo
Aah, I see. Thank you. That helped a lot.