Viktor234 Posted June 6, 2020 Share Posted June 6, 2020 Recently while modding around I did encounter the following feature/bug which kept crashing my client when pressing a certain button: If I use the following code in the console TheInput:AddKeyDownHandler(string.byte('a'),function() for k,v in pairs(TheInput:GetAllEntitiesUnderMouse()) do print(k,v) end end) and press in this case the button 'a' while hovering over an entity, I get normal results like: - Just like I want to have it But when hovering over any HUD like my inventory, I keep getting results like - Looks bugged out and entities which are behind the HUD do not appear at all in this case. It's also annoying because since the results do exist but they aren't able to handle ingame functions like 'GetPosition' or so, the mod just keeps crashing whenever I use it while hovering above the HUD. If I open up my console and input the following code while hovering above the HUD for k,v in pairs(TheInput:GetAllEntitiesUnderMouse()) do print(k,v) end then I get results like that one: - Just like I want to have it But that's not the case if I use the function as a key down handler. Is that an feature/bug which can be avoided by using different commands or anything? Or would I need to wait for Klei to change/fix it? 1 Link to comment https://forums.kleientertainment.com/forums/topic/118842-strange-getallentitiesundermouse-behaviour/ Share on other sites More sharing options...
Hornete Posted June 7, 2020 Share Posted June 7, 2020 On 6/6/2020 at 5:05 PM, Viktor234 said: Is that an feature/bug which can be avoided by using different commands or anything? Or would I need to wait for Klei to change/fix it? Widgets/UI are entities, so the game must be getting these widgets and usually it'd print out its prefab name but of course widgets dont have prefab names so it just appears as nothing. To get rid of widgets/ui from your table you can probably do something like this local ents = TheInput:GetAllEntitiesUnderMouse() for k, v in pairs(ents) do if v ~= nil and v:HasTag("widget") or v:HasTag("UI") then table.remove(ents, k) end end 1 Link to comment https://forums.kleientertainment.com/forums/topic/118842-strange-getallentitiesundermouse-behaviour/#findComment-1340614 Share on other sites More sharing options...
Viktor234 Posted June 8, 2020 Author Share Posted June 8, 2020 11 hours ago, Hornete said: To get rid of widgets/ui from your table you can probably do something like this local ents = TheInput:GetAllEntitiesUnderMouse() for k, v in pairs(ents) do if v ~= nil and v:HasTag("widget") or v:HasTag("UI") then table.remove(ents, k) end end Using this for-loop won't fix 100% of the crashes considering the fact that removing the n-th element of the list will just skip the n+1-th element since lua doesn't recognize in that case that the list became smaller. An one-liner example: list = {1,2,3,4,5,6,7,8} for k, v in pairs(list) do table.remove(list, k) end for k, v in pairs(list) do print(list[k]) end print("done") While this function is supposed to remove all the numbers from the list, it will remove only the numbers 1,3,5,7 and print 2 4 6 8 done A code better suitable for that could be this one: list = {1,2,3,4,5,6,7,8} for k = #list,1,-1 do v = list[k] table.remove(list, k) end for k, v in pairs(list) do print(list[k]) end print("done") Since removing the n-th element in this case won't affect the incoming elements at all, resulting in all of the numbers being removed from the list. Link to comment https://forums.kleientertainment.com/forums/topic/118842-strange-getallentitiesundermouse-behaviour/#findComment-1340678 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now