3.1.0 Impossible to use 'serialMessageReceived' in simulator

,

Hello!

I’m trying to add console commands to my Lua game for the first time and I’m running into a problem that seems like a bug.

function playdate.serialMessageReceived(message)
	print("Message: ".. message)
end

When I type ‘msg test’ in the console I get the following error message in red.

> msg test
[string "console"]:1: syntax error near 'test'

But when I type ‘!msg test’, with the device connected I get the expected printed message.

Message: test

I would expect ‘msg test’ to print the message the same way from the simulator as it does from the connected device, without error messages. This prevents me from using any of my console commands in the simulator.

I’m developing on MacOS with the recently released 3.1.0 SDK update.

looking at the code, it looks like !msg does route the message to the simulator if a device isn't connected. If that's going to cause a lot of unplugging and plugging you could trade it for a bit more typing by adding a shortcut to the callback like:

function msg(message) playdate.serialMessageReceived(message) end
1 Like

Hmm, I feel like I’m missing something basic here…

Is this how you meant for that snippet to be used?

function msg(message) playdate.serialMessageReceived(message) end

function playdate.serialMessageReceived(message)

	print("Message: ".. message)
	
end

It results in exactly the same error messages in the console.

> msg test
[string "console"]:1: syntax error near 'test'

I can confirm that typing !msg in the console with the device disconnected calls the functions as you said in the simulator though! That is a good start and I can definitely work with this. But still confused why this wouldn’t work.

sorry, wasn't clear: you'd call it like msg("test")

1 Like

That works! Thank you Dave! :smile: