From 6e4a76db0862303ae7f0f9fd7bdddff128fbd2f0 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Tue, 28 Mar 2023 20:47:31 -0500 Subject: [PATCH] auto_profiles: check for non-existent properties Previously, it just silently didn't do anything which is not very intuitive. Since the lua api returns an error string, check to see if it matches the "property not found" case and print an error message. Additionally, don't add the fake property to the internal cached_properties list or try to observe it. This avoids redundant evaluate calls which will never actually succeed. We do still mark it under watched_properties however. This avoids having to call mp.get_property_native multiple times. --- player/lua/auto_profiles.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/player/lua/auto_profiles.lua b/player/lua/auto_profiles.lua index f43e6b28f3..55394c2e26 100644 --- a/player/lua/auto_profiles.lua +++ b/player/lua/auto_profiles.lua @@ -87,8 +87,13 @@ function get(name, default) -- Normally, we use the cached value only if not watched_properties[name] then watched_properties[name] = true + local res, err = mp.get_property_native(name) + if err == "property not found" then + msg.error("Property '" .. name .. "' was not found.") + return default + end + cached_properties[name] = res mp.observe_property(name, "native", on_property_change) - cached_properties[name] = mp.get_property_native(name) end -- The first time the property is read we need add it to the -- properties_to_profiles table, which will be used to mark the profile