Save function not being called? [RESOLVED]

function save()
	print("Entered save function")
-- Check if items is defined and not nil
	if items then
		msg.post("menu#PauseMenu", "itemsReady", {itemData = items})
		print("Save Data Posted From Inventory")
	else
		print("Error: items is nil or not defined")
	end
end


function init(self)
	print("Script initialized")
end

function on_message(self, message_id, message, sender)
	print("Received message:", message_id)
	if message_id == hash("fileSave") then
		print("fileSave Inventory")
		save()
	end
end

fileSave inventory is being successfully printed, so I know the message is being received properly, but “Entered save function” is not being outputted

thank you for your help

Is there a duplicate save function somewhere? Maybe try setting your save function to local scope and see if anything changes.

local function save()
1 Like

that fixed it thank you. Though idk why? There isn’t more than one save function in this script, is it because there are multiple save functions throughout the program?

Yes, if you do not prefix the function with the local keyword you get a global function, and if you have multiple global functions they will overwrite each other.

2 Likes