Okie dokie, this is getting too difficult, so while @ego-lay_atman-bay was writing his solution, I worked out with my own, though his solution is easier.
- parallel-run a "simple" script that check if a
ws.msg.new
is true
on my WebSocket variable and if ws.msg
even exists.
- if we got a new message, parse up the spicy JSON object from a string to table, defaulting to a string if failed.
- the rest!!
Oh, by the way, in case you want it, here's a recursive function that turns a list of lists into snap lists.
function toSnapList(arr) {
let newArr = []
for (let item of arr) {
if (Array.isArray(item)) {
item = toSnapList(item)
}
newArr.push(item)
}
return new List(newArr)
}
I figured from reportListAttribute
's code...
// ...
case 'json':
this.assertType(list, 'list');
if (list.canBeJSON()) {
return list.asJSON();
}
throw new Error(
localize('unable to convert to') + ' ' + localize('JSON')
);
// ...
So really I can just new List(...).toJSON()
edit: for the other way 'round
Process.prototype.reportBasicTextSplit
(idk why is it called that if its being directly called from split primitive) calls this.parseJSON(string)
, so I can just practically new Process().parseJSON(JSON.stringify({hehehe: ":stuck_out_tongue_winking_eye:"}))
But all my info was too late to gain since I accidentally stumbled upon both of these ways later than when I was coding in serialization into my project where I needed to find out this useful info. Now I'll know for later...
I also realised that to call a block script you need to instantiate a Process
, then do some secret black magic on it and the editor to actually call the script. Will also be knowing this for later...
source: MQTT extension
Actually, if you do it in a javascript function block, the current Process
object is passed in as the last argument if you have one more parameter than what is passed in with "with inputs", which can be used instead of creating your own process. For example
Is the Process
like a special Process
or is it just a yet another ordinary Process
? I want to know.
EDIT: I know what you mean and your fact
It's the Process
that runs the javascript function block.
Can't really see an use for a pre-instantiated Process
that runs the JS. Maybe for like getting script variables without args?
The object doesn't get destroyed, in fact, you can still run scripts with it later.
Oh. Well that's a nice point to it
You can call a ring by using .invoke btw
That's probably what I meant