Teardown

Teardown

Tool Menu
Fix and reason for the favorite not saving correctly I discovered
#DO NOT COPY CODE SNIPPETS FROM THIS POST#
(For some reason steam is removing things like [ i ] from the post so if you copy codes it may not work)

I think I may have solved the problem by changing the load_favorite_tools() function in main.lua from
function load_favorite_tools() -- load from perst. local fav_string = GetString(favorite_tools_reg) local tool_ids = split(fav_string, ',') -- update the favorite status of the tools for i, tool_id in ipairs(tool_ids) do local index = tonumber(get_tool_key(tool_id, 'index')) if tonumber(index) ~= nil then all_tools[index].favorite = true end end end
to
function load_favorite_tools() -- load from perst. local fav_string = GetString(favorite_tools_reg) local tool_ids = split(fav_string, ',') -- update the favorite status of the tools for i, tool in ipairs(all_tools) do if table_contains(tool_ids, tool.id) then all_tools.favorite = true
end
end
end[/code]
The reason I think that the original code did not work is because of the line
all_tools[index].favorite = true
and specifically the all_tools[index] part. The index variable here is referring to the index value of the tool but for the all_tools table, the index is the order of the items that will be displayed. As during the sorting of generate_all_tools(), the index are changed.
My modified code does as below:
Iterate through every tool in game and see if they are on the list of favorite (read from persistant), if they are flag them.
So the problem with index is mitigated.
However this may be not efficient at all and since I am not very deep into lua programming and theories I do not have an idea of how to improve this.


Also today I was greeted with an error about the generate_all_tools() function that said invalid order function for sorting.
i have managed to mitigate this problem by sorting with id instead of index:
function generate_all_tools() all_tools = {} -- get all tools tool_ids = ListKeys('game.tool') for i, tool_id in ipairs(tool_ids) do tool_data = get_tool_data(tool_id) table.insert(all_tools, tool_data) end -- sort by id function by_id(a, b) if a.id == nil then return true end if b.id == nil then return false end return a.id < b.id end table.sort(all_tools, by_id) end
I am not sure why is this though and made this change as a temporary solution to the problem.


To those who are wondering how to make/apply these changes:
I have forked and made the change on GitHub, simply download the Tool Menu folder in the repo and move it into the mods folder inside the Teardown inside your document folder (C:\Users\[YourUsername]\Documents by default iirc).
But your documents folder may be elsewhere, for example for me it is E:\25408\Documents\.
Then enable the mod ingame on the right in the tab saying Local files

GitHub link to my fork: https://github.com/2540825244/teardown-tool-menu

In future I may put this modification on Steam workshop, or if anyone wants to please do.

edit: format * 2
edit: realize steam don't like [ i ]
Last edited by QTY2540825244yu; 11 Aug, 2022 @ 12:36pm
< >
Showing 1-5 of 5 comments
QTY2540825244yu 9 Aug, 2022 @ 3:57pm 
Why wouldn't the [/code] of the second snippet work rip
QTY2540825244yu 9 Aug, 2022 @ 4:00pm 
Originally posted by QTY2540825244yu:
Why wouldn't the [/code] of the second snippet work rip
Anyone knows steam text format pls help i cant take this anymore after editing and testing codes with np++ as on my gaming laptop there isnt any dev env apart from the bumpy vs2019
QTY2540825244yu 9 Aug, 2022 @ 4:01pm 
just realised, its literally 2am for me rn xDDD
QTY2540825244yu 12 Aug, 2022 @ 1:14pm 
Made a guide to fix the problem on most of the variants of tool menu yourself:
https://github.com/2540825244/teardown-tool-menu/blob/main/Guide.md
or if you want you can view it on my website:
https://blog.qty10.tech/2022/08/en/TeardownToolMenuFixGuide/
< >
Showing 1-5 of 5 comments
Per page: 1530 50