SetCore Notifications broken?

I’m trying to send a client side notification, but it gives me this error:

[color=#ff1100]SetCore: Unexpected error while invoking callback: Attempt to load a function from a different Lua VM[/color]

Here’s some example code:


StarterGui = game.StarterGui


StarterGui:SetCore("SendNotification", {
	Title = 'This is a test',
	Text = 'Hello world!',
	Icon = '',
	Duration = 5,
	Callback = function()
		warn'waffles'
	end
}
)

Am I doing something wrong?

i think you need to do

warn(“waffles”)

warn"waffles" is valid Lua syntax! So is func_call{} (using a table literal). It’s all up to personal preference.

it would be epic if that was what was breaking it, but sadly that’s not ;(

I understand that this might look like JavaScript at first, but I assure you I am attempting to pass a table through that function.

Also,

warn'waffles'

Is fine syntax!

Someone posted in the Faster Lua VM thread with a similar issue. The engineers reply is here:

In the documentation for SendNotification it says the Callback should be of type BindableFunction. Try creating one, passing it in the arguments, and then setting OnInvoke to your function.

3 Likes

How dare you question my waffle syntax.

Here, let me reformat this to something that looks a little nicer:
:slight_smile:

StarterGui = game.StarterGui

info = {
	Title = 'This is a test',
	Text = 'Hello world!',
	Icon = '',
	Duration = 5,
	Callback = function()
		warn'waffles'
	end
}

StarterGui:SetCore("SendNotification",info)

No, you’re supposed to pass a BindableFunction. Here’s how I use it in one of my old games:

local restartFunc = Instance.new("BindableFunction")
restartFunc.OnInvoke = function(text)
	if text == "RESTART" then
		funcs.restartGame()
	end
end

-- later:
if err then
	print("ERROR LOADING BOARD - ",err)
	game:GetService("StarterGui"):SetCore("SendNotification", {
			Title = "Error!",
			Text = "Error loading your board - please restart your game :(",
			Icon = '',
			Duration = 3600;
			Callback = restartFunc,
			Button1 = "RESTART",
	})
end

7 Likes

In Lua, values of certain types are defined in a very specific way. For example, "hello" defines a string literal, 0 is a number (just a number, without quotes), {} (curly brackets) is a table, etc. Functions act in the same way; they’re defined using function(args, ...) code end or simply function() end. In Lua, functions are first-class values, meaning they can be passed to other functions or stored as variables!

local x = function() doStuff() end

Lua has syntactic sugar for this:

local function x() doStuff() end

The reason you sometimes see end) rather than end is because you’re passing a function literal to another function, like Connect. Lua requires that you balance out your brackets, so when you define a function as an argument, you need to make sure you have a closing parenthesis.

someRBXScriptSignal:Connect(function() --[[ this is a function ]] end)
3 Likes