ID:915673
 
(See the best response by GreatFisher.)
Code:
mob
var
Actionsup = 0

obj
proc
GatherUI()
if(usr.Actionsup==0)
overlays += image('BotanyUI.dmi',"Extract")
usr.Actionsup = 1
usr << output ("[usr] attempts to extract [src].", "output1")
else
overlays -= image('BotanyUI.dmi',"Extract")
usr.Actionsup = 0
usr << output ("[usr] no longer attempts to extract [src].", "output1")

obj
Lilac
Lilac
icon = 'Lilac.dmi'
icon_state = ""
layer = 7
Click(location,control,params)
var/p=params2list(params)
if(p["right"])
GatherUI()


Problem description:

I'm trying to make a UI for displaying interaction options an object has. However, I can't seem to get the code to do what I want. The code I have works fine when dealing with one plant alone, but when I have two or more and I right click on one, then the other, it doesn't close the first one. Instead, both have a UI up. I need to make right clicking on one close any other UI that is up before bringing up a new one.
Best response
Okay first you shouldn't really be using usr in anything other than a verb, it can cause all sorts of unexpected bugs. Second I suggest you maybe use F_A's visibility Groups library to mke each UI visible to only the person that made it(not really mde it but you get my point).

Now for your actual problem I would go with something like this:
mob
var
Actionsup = 0
obj/currentUI
UI

obj
proc
GatherUI(mob/m)
if(!m.Actionsup)
m.Actionsup = 1
m.currentUI = src
m.UI = image('BotanyUI.dmi',"Extract")
src.overlays += m.UI
m << output ("[m.name] attempts to extract [src.name].", "output1")
else
if(!m.currentUI) CRASH("Expected a value for [m].currentUI")
if(!m.UI) CRASH("Expected a value for [m].UI")
m.currentUI.overlays -= m.UI
m.Actionsup = 0
m.currentUI = null
m.UI = null
src.GatherUI(m)//I put this here as I assumed you would want it to display the UI for the thing you just clicked.

obj
Lilac
Lilac
icon = 'Lilac.dmi'
icon_state = ""
layer = 7
Click(location,control,params)
var/p=params2list(params)
if(p["right"])
GatherUI(usr)//it's mostly okay to use usr here because click only come from usr.

Hope this helps.
Yea, I was going to do the client based visibility after I got the thing working correctly. The code you made works perfect on two plants, but now it won't close the UI when I click on the plant with the UI up. I can fix that, though. Thank you for the help and the tip about using usr.