ID:1215668
 
Keywords: button, hud, icon
(See the best response by Fushimi.)
Code:
obj/Button
icon='buttons.dmi'

New(i_state,alt_icon)
..()
if(alt_icon) //Change the icon file
icon=alt_icon
if(i_state) //Set the icon_state
icon_state = i_state

mob/proc/CreateHUD()
//A button with the original icon file
src.client.screen += new/obj/Button(i_state="Save")
//A button with the BIGbuttons.dmi icon file
src.client.screen += new/obj/Button(i_state="Logout",alt_icon='BIGbuttons.dmi')


Problem description:I'm trying to change the icon file of an object when it is created, though it doesn't appear to be working.

Have you tried without using named arguments?
Also, are you sure you have set a proper screen_loc variable to the object being created?
Name arguments?

Ah, what I posted was shorted down to show the problem, the screen_loc is set. In the example, the first button is created and shown fine, the problem occurs when I set the alt_icon when creating a button.
Best response
If it is longer than the snippet shown, could you please post it, so I can look the problem deeper?

The above snippet looks fine to me, so the problem could be elsewhere.
Named args don't matter in this case. The only problem here is that he has changed the representation of the object.

Remove the object from the list, then add it back to show the changes.
Wouldn't just calling the parent proc after the icon change avoid the remove/add process?
Seems the error was on my end, I used alt_icon when creating a new button, but not in the proc I was using to create the button. My code is pretty jumbled at the moment, so it would have been a nightmare to post, but you were right Fushimi, the problem was elsewhere.

Did a little test on the code I used in my first post, it works fine (once a screen_loc is added of course). Thanks guys, final snippet for future references.

obj/Button
icon='buttons.dmi'
New(s_loc,i_state,alt_icon)
..()
if(s_loc)
screen_loc=s_loc
if(alt_icon) //Change the icon file
icon=alt_icon
if(i_state) //Set the icon_state
icon_state = i_state

mob/proc/CreateHUD()
//A button with the original icon file
src.client.screen += new/obj/Button("3,3",i_state="Save")
//A button with the BIGbuttons.dmi icon file
src.client.screen += new/obj/Button("1,1",i_state="Logout",alt_icon='BIGbuttons.dmi')

mob/Login()
..()
CreateHUD()