Page 1 of 1

How do I access the event when left clicking entity

Posted: Sun Sep 02, 2018 5:52 pm
by unhott
I'm trying to add a function when a user left clicks on an entity and I am having trouble.
Anyone have any insights?

Re: How do I access the event when left clicking entity

Posted: Mon Sep 03, 2018 8:37 am
by bobingabout
https://lua-api.factorio.com/latest/
You probably want to look for on_gui_opened, since clicking an entity usually opens a GUI.
You can then look at the entity variable to test it's type and name to see if it's the entity you want.

Re: How do I access the event when left clicking entity

Posted: Mon Sep 03, 2018 10:55 am
by eradicator
You should describe what you actually want to do. More experienced modders might know a better method to achieve what you want. Hooking all left-clicks sounds excessive unless you're trying to write some sort of debug tool ;).

Re: How do I access the event when left clicking entity

Posted: Tue Sep 04, 2018 9:06 am
by bobingabout
Yeah... I mean, you could write your own event triggered by left click, and then when it triggers check to see if there's an entity selected. I'm not going to go into that though unless you come back and request it.
It's a bit more involved, and I can't spare that time right now.

Re: How do I access the event when left clicking entity

Posted: Tue Sep 04, 2018 10:38 am
by eradicator
bobingabout wrote:Yeah... I mean, you could write your own event triggered by left click, and then when it triggers check to see if there's an entity selected.
That's the wrong approach btw. But i don't want to write details about how to do it correctly unless OP gives a very good reason he actually needs that.

Re: How do I access the event when left clicking entity

Posted: Wed Sep 05, 2018 8:22 am
by bobingabout
eradicator wrote:
bobingabout wrote:Yeah... I mean, you could write your own event triggered by left click, and then when it triggers check to see if there's an entity selected.
That's the wrong approach btw. But i don't want to write details about how to do it correctly unless OP gives a very good reason he actually needs that.
I never really was that up on the scripting side, back in the early days, scripting broke things, so one of the promises of my mod was that I'd try to solve everything without using multiplayer breaking or game slowdown scripting.
and I've pretty much kept that promise, there is scripting in select places where it was required, but nothing that should break multiplayer or cause slow downs.

in any case, there are a lot of ways to do things, and some are better than others.

Re: How do I access the event when left clicking entity

Posted: Mon Sep 10, 2018 11:50 pm
by unhott
bobingabout wrote:
eradicator wrote:
bobingabout wrote:Yeah... I mean, you could write your own event triggered by left click, and then when it triggers check to see if there's an entity selected.
That's the wrong approach btw. But i don't want to write details about how to do it correctly unless OP gives a very good reason he actually needs that.
I never really was that up on the scripting side, back in the early days, scripting broke things, so one of the promises of my mod was that I'd try to solve everything without using multiplayer breaking or game slowdown scripting.
and I've pretty much kept that promise, there is scripting in select places where it was required, but nothing that should break multiplayer or cause slow downs.

in any case, there are a lot of ways to do things, and some are better than others.

I stumbled into what you were talking about here, bob. I didn't realize custom inputs could have key sequence = mouse-button-n. I like that approach. I don't mind if I break multiplayer for now. I just want a working proof of concept.

Re: How do I access the event when left clicking entity

Posted: Mon Sep 10, 2018 11:51 pm
by unhott
Thank you all for your replies!

I'm stoked. I think I can get my mod working how I want it (for now)!

Re: How do I access the event when left clicking entity

Posted: Tue Sep 11, 2018 12:49 pm
by eradicator
unhott wrote: Mon Sep 10, 2018 11:50 pm I didn't realize custom inputs could have key sequence = mouse-button-n.
Gnarf. Please use a linked_game_control instead of an arbitrary mouse button if you're going that way...
(The wiki seems down so i can't post a link.)

Re: How do I access the event when left clicking entity

Posted: Tue Sep 11, 2018 1:00 pm
by Bilka
eradicator wrote: Tue Sep 11, 2018 12:49 pm Gnarf. Please use a linked_game_control instead of an arbitrary mouse button if you're going that way...
(The wiki seems down so i can't post a link.)
https://wiki.factorio.com/Prototype/Cus ... me_control :)

Re: How do I access the event when left clicking entity

Posted: Tue Sep 11, 2018 4:06 pm
by eradicator
Bilka wrote: Tue Sep 11, 2018 1:00 pm
eradicator wrote: Tue Sep 11, 2018 12:49 pm Gnarf. Please use a linked_game_control instead of an arbitrary mouse button if you're going that way...
(The wiki seems down so i can't post a link.)
https://wiki.factorio.com/Prototype/Cus ... me_control :)
I still get a 404 on that.

Re: How do I access the event when left clicking entity

Posted: Tue Sep 11, 2018 4:18 pm
by Bilka
eradicator wrote: Tue Sep 11, 2018 4:06 pm I still get a 404 on that.
ctrl + F5, restarting my browser, or using a private window have helped for that throughout today, though for me everything is working now.

Re: How do I access the event when left clicking entity

Posted: Tue Sep 11, 2018 4:45 pm
by eradicator
Bilka wrote: Tue Sep 11, 2018 4:18 pm
eradicator wrote: Tue Sep 11, 2018 4:06 pm I still get a 404 on that.
ctrl + F5, restarting my browser, or using a private window have helped for that throughout today, though for me everything is working now.
Refreshing did indeed work. Why is the wiki redirecting from wiki.factorio.com to wikix.factorio.com though?

Re: How do I access the event when left clicking entity

Posted: Wed Sep 12, 2018 8:16 am
by bobingabout
they just updated the forum software, maybe they're experimenting with a wiki update too?