Page 1 of 1

option for LuaForce.clear_chart to not remove tags

Posted: Mon Mar 14, 2022 12:37 pm
by thesixthroc
For a mod I'm making, I'd like to be able to clear the chart without tags disappearing. I assume that clear_chart just nils the chart, but would it be possible to provide a way to clear the chart but leaving the tags?

Re: option for LuaForce.clear_chart to not remove tags

Posted: Mon Mar 14, 2022 10:35 pm
by Rseding91
Unfortunately; no. The tags are stored directly on the chart itself so if the chart is removed so are the tags.

Re: option for LuaForce.clear_chart to not remove tags

Posted: Tue Mar 15, 2022 7:58 am
by Stringweasel
You could always work around it. Use find_chart_tags to find all the tags in the area you want to clear and remember them, and after you cleared the chart you add_chart_tag them all back in.

Re: option for LuaForce.clear_chart to not remove tags

Posted: Tue Mar 15, 2022 10:55 am
by curiosity
Stringweasel wrote:
Tue Mar 15, 2022 7:58 am
You could always work around it. Use find_chart_tags to find all the tags in the area you want to clear and remember them, and after you cleared the chart you add_chart_tag them all back in.
It's more complicated than that:
add_chart_tag wrote:Note
The chunk must be charted for a tag to be valid at that location.

Re: option for LuaForce.clear_chart to not remove tags

Posted: Tue Mar 15, 2022 11:46 am
by Stringweasel
curiosity wrote:
Tue Mar 15, 2022 10:55 am
It's more complicated than that:
Ahh, thought there might be something like that lurking with Rseding said that tags are stored in the chart. Thanks for clarifying :)

Re: option for LuaForce.clear_chart to not remove tags

Posted: Fri Mar 18, 2022 12:08 am
by BenSeidel
Stringweasel wrote:
Tue Mar 15, 2022 7:58 am
could always work around it. Use find_chart_tags to find all the tags in the area you want to clear and remember them, and after you cleared the chart you add_chart_tag them all back in.
This would work if you store the tags when the chunk is cleared, but restore them in the on_chunk_charted event

Re: option for LuaForce.clear_chart to not remove tags

Posted: Fri Mar 18, 2022 9:07 pm
by thesixthroc
There is a subtle reason I haven't tried; I want to perform this action every tick, on multiplayer. Ne pas.

Re: option for LuaForce.clear_chart to not remove tags

Posted: Sat Mar 19, 2022 4:15 am
by curiosity
thesixthroc wrote:
Fri Mar 18, 2022 9:07 pm
There is a subtle reason I haven't tried; I want to perform this action every tick, on multiplayer. Ne pas.
If you just want to get rid of the mapping of terrain, you can set map size to something very small and generate the actual map during runtime.

Re: option for LuaForce.clear_chart to not remove tags

Posted: Sat Mar 19, 2022 9:58 am
by Qon
thesixthroc wrote:
Fri Mar 18, 2022 9:07 pm
There is a subtle reason I haven't tried; I want to perform this action every tick, on multiplayer. Ne pas.
Setting a chart tag shouldn't be extremely expensive. It should be very cheap even if it's done in lua compared to chunk generation. Restoring chart tags every tick is possible to do quickly if you use tables with chunk location as index.