[Solved] How do I make a structure do something at regular intervals?
[Solved] How do I make a structure do something at regular intervals?
So I have a structure which is supposed to do something every X amount of time/ticks, similar to how radars works (but faster). since this is the first time I worked with anything like this, I have no idea how to do it.
Edit: I figured out how to use on_tick and find_entities_filtered to do what I want, so unless there is a better way, that's what I'm using.
Edit: I figured out how to use on_tick and find_entities_filtered to do what I want, so unless there is a better way, that's what I'm using.
Last edited by Yemto on Tue Apr 30, 2019 6:41 pm, edited 1 time in total.
Re: How do I make a structure do something at regular intervals?
You could look at how Scanning Radar or Big Brother do things?
Re: How do I make a structure do something at regular intervals?
I just looked at Bob's warfare and Big Brother, and both mods seem to just use/modify the vanilla functionality of the radar, which I can't use since my structure I'm making is not going to the same thing as a radar.
Re: How do I make a structure do something at regular intervals?
That's why I suggested Scanning Radar as well; it provides a 'radar', that does all of the work via scripting in order to scan a circular area, rather than a square area.
Re: How do I make a structure do something at regular intervals?
How do I look at vanilla entities? "data/core" and "data/base" doesn't have a radar script.
Re: How do I make a structure do something at regular intervals?
The best way is to find a vanilla entity that can be modified to do what you need. If that is not possible, you will have to write a script and run it in on_tick or on_nth_tick. In that case, make sure to keep what you are doing to a minimum. Calling find_entities_filtered on every tick will quickly get you into UPS-drop territory. A better approach is to keep a list of your custom entities and use that instead.
You can't. Vanilla entity behavior is not written in Lua.Yemto wrote: Tue Apr 30, 2019 9:24 am How do I look at vanilla entities? "data/core" and "data/base" doesn't have a radar script.
Re: How do I make a structure do something at regular intervals?
eduran wrote: Tue Apr 30, 2019 10:37 am The best way is to find a vanilla entity that can be modified to do what you need. If that is not possible, you will have to write a script and run it in on_tick or on_nth_tick. In that case, make sure to keep what you are doing to a minimum. Calling find_entities_filtered on every tick will quickly get you into UPS-drop territory. A better approach is to keep a list of your custom entities and use that instead.
Ok, thanks. That's what I have been doing so far. While I'm new to Factorio modding, but I have been programming for quite a while I know to avoid things like that.
Edit: Just a quick question, can I store custom variables in entities? or do I have to set up my own tables for that?
- AmatorPhasma
- Fast Inserter
- Posts: 126
- Joined: Sat Aug 05, 2017 8:20 pm
- Contact:
Re: How do I make a structure do something at regular intervals?
No not possible for the entity or the prototype, you have to setup your own global.table,Yemto wrote: Tue Apr 30, 2019 11:23 ameduran wrote: Tue Apr 30, 2019 10:37 am The best way is to find a vanilla entity that can be modified to do what you need. If that is not possible, you will have to write a script and run it in on_tick or on_nth_tick. In that case, make sure to keep what you are doing to a minimum. Calling find_entities_filtered on every tick will quickly get you into UPS-drop territory. A better approach is to keep a list of your custom entities and use that instead.
Ok, thanks. That's what I have been doing so far. While I'm new to Factorio modding, but I have been programming for quite a while I know to avoid things like that.
Edit: Just a quick question, can I store custom variables in entities? or do I have to set up my own tables for that?
somthing like:
Code: Select all
global.my_table[entity.unit_number] = somthing or {somthing=somthing, ...}
Re: How do I make a structure do something at regular intervals?
Ok, thanks so much.AmatorPhasma wrote: Tue Apr 30, 2019 11:57 amNo not possible for the entity or the prototype, you have to setup your own global.table,Yemto wrote: Tue Apr 30, 2019 11:23 ameduran wrote: Tue Apr 30, 2019 10:37 am The best way is to find a vanilla entity that can be modified to do what you need. If that is not possible, you will have to write a script and run it in on_tick or on_nth_tick. In that case, make sure to keep what you are doing to a minimum. Calling find_entities_filtered on every tick will quickly get you into UPS-drop territory. A better approach is to keep a list of your custom entities and use that instead.
Ok, thanks. That's what I have been doing so far. While I'm new to Factorio modding, but I have been programming for quite a while I know to avoid things like that.
Edit: Just a quick question, can I store custom variables in entities? or do I have to set up my own tables for that?
somthing like:Code: Select all
global.my_table[entity.unit_number] = somthing or {somthing=somthing, ...}
Re: [Solved] How do I make a structure do something at regular intervals?
Two remarks to help with this approach:AmatorPhasma wrote: Tue Apr 30, 2019 11:57 amCode: Select all
global.my_table[entity.unit_number] = somthing or {somthing=somthing, ...}
- There is no way to get an entity from its unit_number. If you need to access the actual entity in your script, you should store it:
Code: Select all
global.my_table[entity.unit_number] = {entity = entity, userdata = my_data, ...}
- You should subscribe to on_robot_mined_entity, on_pre_player_mined_item and on_entity_died events to remove invalid entities from your table.