Script.post "Invalid JSON Data" Error

I’ve been trying to organize some of my scripts so I can share code between many scripts intended for different rooms. I can’t tell if I’m just going too many functions deep, it doesn’t like how I used namespaces, or that I’m calling Script.post from imported code but sometimes Script.post throws an “invalid json data” when the code previously had no issue.

There’s an error with the version of json-as that earlier versions of muclet-script, make sure to update mucklet-script to version 1.65.1 1.65.2 or later and it should start working again.

Edit: my mistake, thanks Accipiter!

I’m already using 1.65.1

The JSON deserialization issue was resolved in Mucklet Script v1.65.2 (not v1.65.1).

So, try do a:

npm install mucklet-script@latest

If the problem remains, it may be something else. Though, then I would probably need to look at your code to get a better understanding.

I just updated it but I’m still getting that error.

I also tried helping Ace with an issue he was having with the lock_outside example script earlier today but I couldn’t figure it out. He was getting ‘error parsing script: “exitAction.cancel” is not exported in module “env”’

Do you have the script uploaded anywhere, like GitHub or BitBucket?
If so, I can have a look at it.

This one is slightly peculiar. It is most likely a bug in the part of my code that tries to handle scripts made for older versions of the server. (exitAction.cancel was exported as exitIntercept.cancel prior to v1.65.0)

I’ll try to contact Ace and see how I can help him (or rather, how he can help me find the bug causing it!).

I just uploaded it to GitHub. It’s a bit messy since I was copying the main part of my code to different files to try and fix this but all of it is in nora-main-room and nora-tree-house.

1 Like

Sorry @cade_trigon for the delay in replying.
While it may not be related (or it may be), the “Invalid JSON Data” may be fixed by upgrading mucklet-script as I mentioned in this thread: Script memory bug

Now that this bug if resolved, I more properly check the other script issues!

A belated response. Hopefully not too late!
I’ve been checking your code (Nice, by the way! :smiley:) , and I see one issue.

The data string passed to Script.post must be a valid JSON encoded string:

That means, in scripts/nora-main-room.ts, you would rather have to write:

Script.post(listenerRoomScripts[i], TopicKeyword.weatherTick, JSON.stringify(getStoredKeyword()));

And subsequently in scripts/listener/index.ts and scripts/nora-main-room.ts, decode it:

ListenerWeather.set(JSON.parse<string>(data));

It is surely not obvious that you can’t just pass any string as data. Hopefully I can improve it in later version. But I believe this is what causes the issue.

Oh, and then I recommend upgrading mucklet-script to latest, as a rather nasty memory corruption but caused very random issues.