How do I access the event when left clicking entity

Place to get help with not working mods / modding interface.
Post Reply
unhott
Inserter
Inserter
Posts: 29
Joined: Tue Jan 09, 2018 3:01 am
Contact:

How do I access the event when left clicking entity

Post 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?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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 ;).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

unhott
Inserter
Inserter
Posts: 29
Joined: Tue Jan 09, 2018 3:01 am
Contact:

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

Post 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.

unhott
Inserter
Inserter
Posts: 29
Joined: Tue Jan 09, 2018 3:01 am
Contact:

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

Post 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)!

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post 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 :)
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

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

Post by bobingabout »

they just updated the forum software, maybe they're experimenting with a wiki update too?
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding help”