ID:793710
 
(See the best response by DarkCampainger.)
Code:
atom
Click()
var/mob/M = usr
if(M.Click_Listener)
var/datum/Click_Listener/CL = M.Click_Listener
if(istype(src, CL.clickType))
CL.clickHeard = src
return


Problem description:

I'm trying to make a library that allows the dev to call a proc that returns the first atom of /type that the player clicks on.

The problem is that for this to be plug and play, I can't just override Click(). Is there a way to do this without giving them a hook to copy and paste into their Click() proc?

EDIT: If the code is confusing, sorry. It's irrelevant to the problem, as I just need to know if there's a good way to get it into the default Click() without overriding.
Best response
If I'm understanding you correctly, a similar library exists: Garthor's GetClick.

You could see how he did it, or if it suits your needs, just use it.

It looks like he just overrode client/Click(), and called the parent process with ..() to make sure it didn't override any competing definitions from the library's users.
Ah, cool. I've been trying to write all of my material, but I'm sure I can learn something from it.

EDIT: Wow, I had somehow missed client/Click(). That would've made everything about 100% easier. Ah well, it works.
You're going to have to override something. If someone uses your library and overrides the same proc you're using, they'll have to call ..() to trigger your proc. Using client/Click() is probably safer since people are more likely to override atom/Click without calling ..(), but it can't be avoided completely. If people override mob/Move() they have to call ..() to run BYOND's default movement action - this is just something people need to get used to.
Just so I understand:

If I have a library that does this:
atom
Click()
src.stuffAtomsDo()


and in their code:
atom
Click()
src.personalCode()
..()


Will src.stuffAtomsDo() get called? I didn't think this would work (at least, according to F1). I noticed these don't seem to cause a conflict (maybe I was doing it wrong).

IE, how does the program know which Click() to call?
It's going to call the one closest to them.

If they are using mob/Click() and put ..() in it, theirs will call first, then their atom/Click() will be called, and then yours will get called.

If they are using atom/Click(), theirs will be called, and then (assuming they have ..()) yours will be called.

An example:
atom/Click()
src << "Atom"
..()

mob/Click()
src << "Mob"
..()

mob/player/Click()
src << "Player"
..()

world/mob = /mob/player

The code above, when you click yourself, will result in the following output:

Player
Mob
Atom
In response to Jazztoken (#4)
My guess would be the one last to override is the first to call, but this will probably get confusing and messy depending on where you put ..(), which is what ties them together. In your code, src.personalCode() might never get called if the first snippet is placed below the second, because in the override that calls src.stuffAtomsDo(), there is no ..() call to let the src.personalCode() override work.
In response to Kaiochao (#6)
Kaiochao wrote:
My guess would be the one last to override is the first to call, but this will probably get confusing and messy depending on where you put ..(), which is what ties them together. In your code, src.personalCode() might never get called if the first snippet is placed below the second, because in the override that calls src.stuffAtomsDo(), there is no ..() call to let the src.personalCode() override work.

This is why I make it a habit to put ..() in every built-in proc that I override, because I don't want to screw something up and take forever trying to find out why.

You may want to do the same, Jazztoken.