I've made a simple, lightweight, variable change detector. Using tables to check if a variable is different from its most recently saved value, should work with true & false, numbers, strings, etc. If there are any errors, let me know.
(Note the image is a separate version which uses print to show the result; this is meant to be used as a function you can either put in a lua file or use in require, and as such returns a true or false on change detection)
Simple lightweight variable change detector
-
- Prole
- Posts: 1
- Joined: Wed Feb 28, 2024 4:59 pm
Simple lightweight variable change detector
- Attachments
-
- main.lua
- (464 Bytes) Downloaded 167 times
- BrotSagtMist
- Party member
- Posts: 659
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Simple lightweight variable change detector
There is nothing simple nor lightweight about this.
Inserting and removing in a table like that is the very thing you try to avoid with such checks. Because that is really adding cpu usage.
Here is a lighter version that works without.
Inserting and removing in a table like that is the very thing you try to avoid with such checks. Because that is really adding cpu usage.
Here is a lighter version that works without.
Code: Select all
do
local switch
function detectChange(v)
if switch==v then
return false, v, v
else
local _ =switch
switch=v
return true, _,v
end
end
end
obey
Who is online
Users browsing this forum: No registered users and 2 guests