Building template causes lua error

Summary:
I get an lua error direct after loading the save file.

Steps to reproduce:
hard to say. Last think i done was building on my watchtower template (attached as “wachturm wood” and “wachturm (wood)”). I build one version, saved it, edited it before building, change the design and saved it again with the same name, this looks bugy (I think the error shows up as first time).
Then i saved it under an differtend name (“wachturm (wood)”) and close the game.
after restarting the game, it comes very time i start the game.

I maybe has to do with a goblin fight in the same area before.

Expected Results:

Actual Results:
develop-2969 (x64)…onehearth/components/building/building_component.lua:328: attempt to index local ‘entity’ (a nil value)stack traceback:
radiant/modules/common.lua:237: in function ‘report_traceback’
radiant/modules/common.lua:248: in function <radiant/modules/common.lua:242>
…onehearth/components/building/building_component.lua:328: in function ‘_trace_entity’
…onehearth/components/building/building_component.lua:123: in function ‘_restore_structure_traces’
…onehearth/components/building/building_component.lua:77: in function ‘obj’
radiant/modules/events.lua:73: in function ‘instance’
radiant/modules/events.lua:206: in function <radiant/modules/events.lua:200>
[C]: in function ‘xpcall’
radiant/modules/common.lua:257: in function ‘xpcall’
radiant/modules/events.lua:200: in function <radiant/modules/events.lua:171>

Notes:
played in hard mode, for me it looks like the template causes the error

Attachments:
error_on_loading.zip (7.6 MB)
building_templates.zip (4.6 KB)

Version Number and Mods in use:
develop 2969, no mods in use

1 Like

Summary:
So one day i was designing a giant castle, but it must have gotten bugged because an error message kept popping up. It didn’t crash the game or anything, so i took no notice and constantly closed the report. However, i soon realized that when i tried to save the castle’s template, it hung the game. I then deleted my castle and proceeded to expand my town, but i realized that all my previous building templates were gone, and when i clicked on building templates, the same error message will pop up. I decided to start a new game to see if the problem was with the old one, but to my dismay my building templates were still gone when i tried to build something. I’m not sure what helps but here is the error message.

develop-2972 (x64)
stonehearth/lib/build_util.lua:482: attempt to index local ‘template’ (a nil value)
stack traceback:
[C]: ?
stonehearth/lib/build_util.lua:482: in function 'get_templates_for_kingdom’
stonehearth/call_handlers/build_call_handler.lua:41: in function <stonehearth/call_handlers/build_call_handler.lua:39>

Hello @Fabian_Tan, welcome to the forum :smiley:

My goodness, that sounds like a really horrible bug :sweat:

Could you check if you still have the template files (it could be the game not being able to read them). Go to C:\Program Files (x86)\Steam\steamapps\common\Stonehearth\saved_objects\stonehearth\building_templates folder and see if there are any files there.

I’m getting this same error:

release-553 (x64)
c++ exception: lua runtime error
stack traceback:

release-553 (x64)
stonehearth/lib/build_util.lua:482: attempt to index local 'template' (a nil value)
stack traceback:
	[C]: ?
	stonehearth/lib/build_util.lua:482: in function 'get_templates_for_kingdom'
	stonehearth/call_handlers/build_call_handler.lua:41: in function <stonehearth/call_handlers/build_call_handler.lua:39>

I’ve actually been getting this error since Alpha 14 at least (this is the first time I’ve reported, though). My building_templates folder is still full of templates, and even new buildings that I designed and saved in the last couple days are there. Still, nothing shows in my building templates in-game. I only get the error once per reload.

I’ve also noticed, looking in that folder, that use of non-alphanumeric characters in the in-game name of the template can cause problems in the actual folders. For example, I named one template “small house w/ loft” in-game which was translated into a folder titled “small house w” containing the file " loft.json".

1 Like

Thanks @FoldableHuman :smiley:

I got this error as soon as I tried to save a template with a slash in the name. The template was not saved, but an empty folder with the truncated name appeared in my templates folder.

Well, it was not exactly the same error but pretty close (I’m still in dev2972):
-- Script Error (lua) Begin ------------------------------- ...ervices/client/build_editor/build_editor_service.lua:438: attempt to index upvalue 'template' (a nil value) stack traceback: [C]: ? ...ervices/client/build_editor/build_editor_service.lua:438: in function 'finish_fn' ...ient/portrait_renderer/portrait_renderer_service.lua:66: in function <...ient/portrait_renderer/portrait_renderer_service.lua:58> -- Lua Error End -------------------------------

Paging @sdee and @not_owen_wilson

1 Like

Hi @Relyss,

Thanks for replying. Apparently all my templates are still there. Even in new games, when i try to build from a template or save a building template, i’ll get a error message, but usually i’ll just close permanently and nothing else happens. Thankfully i’m able to continue my games, while just not being able to save and use templates.

1 Like

stimilar thing for me
https://discourse.stonehearth.net/t/templates-not-shown/28527

release-949 (x64)[M]
c++ exception: wide utf character (hilo)
stack traceback:
[C]: in function ‘load_custom_building_template_headers’
…services/client/building/building_client_service.lua:278: in function ‘_collect_custom_templates’
…services/client/building/building_client_service.lua:99: in function ‘initialize’
stonehearth/stonehearth_client.lua:23: in function ‘create_service’
stonehearth/stonehearth_client.lua:50: in function <stonehearth/stonehearth_client.lua:44>
[C]: ?
[C]: in function ‘trigger’
radiant/modules/events.lua:55: in function <radiant/modules/events.lua:55>