ID:888003
 
Keywords: hud, icon, icons, settings, sound
(See the best response by Albro1.)
Code:
obj
SettingsDown
name = "Settings Down"
icon = 'Buttons2.dmi'
screen_loc = "16,3"
icon_state = "down"
layer = MOB_LAYER+999
Click()
usr.client.screen-=new/obj/Sound
usr.client.screen-=new/obj/SettingsDown
usr.settingsopen=0
Settings
name = "Settings"
icon = 'Buttons2.dmi'
screen_loc = "16,1"
icon_state = "settings"
layer = MOB_LAYER+999
Click()
if(usr.settingsopen==0)
usr.client.screen+=new/obj/Sound
usr.client.screen+=new/obj/SettingsDown
usr.settingsopen=1


Problem description:
Hi guys, i'm working on these HUD icons on screen and they work fine all together the only thing is i made this "Settings" icon wich is supposed to when clicked on show some more icons above it for like sound. Now the problem is they do show up but when clicked on another HUD icon they dont disappear.
I tried working with mouse_opasity but that didnt work either. Does someone see the problem in my code?

Thank you,
Chaokai
Best response
You have to reference it, just like images in your other topic. You can't create a new object and try to take it off of the player's screen, because it isn't there. You have to take off the object that's already there.
Thank you albro1 i thought up of something and it works ;)

SettingsDown
name = "Settings Down"
icon = 'Buttons2.dmi'
screen_loc = "16,3"
icon_state = "down"
layer = MOB_LAYER+999
Click()
for(var/obj/Sound/o in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
usr.client.screen-=o
for(var/obj/SettingsDown/p in usr.client:screen)//this will search your screen to see if there is any obj/hub's on it
usr.client.screen-=p
usr.settingsopen=0
You don't need the colons in usr.client:screen. Just do usr.client.screen. You can also back that second for loop by a tab.
Again, every time you create an object, it is a completely different thing. For a list of objects, imagine you have a bag of apples. It doesn't make sense to create an apple and try to remove it from the bag it isn't even in.

If you add an apple that you plan on removing later, you could tie a string to it and let the string hang out of the bag. When you want to remove it, you'd pull the string. That's like making a variable outside the bag to use to access the specific apple.