Kampfkarren's Database2 Help!

I am creating a system mixed for saving data in a very compact form factor, using a custom function and another module by Stravent called “BitBuffer”. What BitBuffer essentially does is convert a string/bool/int/float to bytes which then can be converted into a Base64 String. What i am using is the string feature of BitBuffer with my table shrinker function to essentially keep a table’s storage footprint on the server at an absolute low, to allow a mass storage of items/ things.

What i really want to do is have this all “computed” beforeinitalget and beforesave, which is already possible with kampfkarren’s Database2, but for some odd reason beforesave is not executing the function, and is just instantly saving data.

My script for BeforeSave:

data:BeforeSave(function(dat)
	print("Is This SAVING??");
	if type(dat)=="table" then
		dat= shrinkTable(dat);
		dat= HTTP:JSONEncode(dat);
	end
	
	BBuffer:Reset();
	BBuffer:WriteString(dat);
	return BBuffer:ToBase64();
end);

The above is appearently not executing, hence why i have the print before anything is executed.
I have had BitBuffer work before, but it is my first time transforming a table that has string keys to a full blown number array. Im not sure if the error is in that function or not, seeing as a test on dummy data with that function seems to work great.
The Function at hand.

function shrinkTable(data)
	local tbl= {};
	
	local count=1;
	for i,v in pairs(data) do
		if i=="Equipped" then
			local coun=1;
			local g= {};
			
			for _,y in pairs(v) do
				g[coun]= y;
				coun=coun+1;
			end
			v=g;
		end
		
		if i=="Inv" then
			local k= {};
			
			for c,x in ipairs(v) do
				local f={};
				local coun=1;
				for _,z in ipairs(x) do
					f[coun]= z;
					
					coun=coun+1;
				end
				k[c]= f;
			end
			v=k;
		end
		tbl[count]= v;
		count=count+1;
	end
	return tbl;
end

The above seems to work well with dummy data. The issue seems that Database2 isnt calling it, or isnt calling BeforeSave in general. BeforeInitalGet works as intended, but because it accounts for data being compressed, it tends to error. The only weird aspect is why BeforeSave isnt even executed as no errors are outputted to log.
I am requiring the module via id, which means it is at it’s current update. BeforeSave also works in other instances like when just using BitBuffer.

(EDIT:
If you want to see what the test for the shrink function returns. It returns:
[[],5,[[0,0,0],0,0,0,[0,0,0]],50]
This is the table when unshrunk:
{"Credits":5,"Equipped":{"MPerks":[0,0,0],"SAbil":0,"MSkin":0,"MAbil":0,"SPerks":[0,0,0]},"Coins":50,"Inv":[]})

UPDATE: Turns out i dont think BeforeSave is ever called… I just tried an old script from a game that use to work, and BeforeSave did not work! Could be an issue with BitBuffer as both used it, but the script use to work fine. Ill look into this

2 Likes