Simulator
Enums
Enums (and interfaces) can be shared between simulator and the target libraries
if you put them in the library, in .d.ts
file, and then reference these
files from the simulator.
Compilation to ARM native code
If your target platform is ARM Mbed compatible, PXT will be able to compile programs to ARM machine code in browser. We recommend to contact the team to help you get started on this topic.
Async functions
PXT support cooperative multithreading and implicit async functions. See more.
Offline Support
If your simulator references images or external resources then it might not work
when offline. You can fix this by configuring the service worker for the simulator
that PXT creates. Inside of your target’s sim/public
folder, add a file named
workerConfig.js
with the following contents:
self.setSimulatorWorkerOptions({
urls: []
})
Any URLs that are placed in the urls array will be cached along with the other simulator
files. If the URLs are located in the sim/public
folder of your target, you can reference
them like so: /sim/myFile.png
. The /sim/
path component will be automatically patched
by PXT into the full URL for the resource.
Warning: Make sure that all URLs added to this array exist. If any of these URLs fail to resolve, the service worker will not install and the simulator will not be cached offline.
Message simulators
It is possible to register external simulator that will get spawned once a specific channel of a control sim message is detected. This feature is used to spawn domain-specific simulators.
To enable this scenario, you will have to add the mapping of control message channels to simulator URLs (and other options)
in pxtarget.json
under the simulator.messageSimulators
field:
...
simulator: {
...
messageSimulators: {
...
"mychannel": {
"url": "url of the simulator$PARENT_ORIGIN$",
}
}
}
When loading the message simulator url, MakeCode expands $PARENT_ORIGIN$
with the URI-encoded origin of the editor.
You can use this value to validate the origin of iframe messages.
Similarly, $LANGUAGE$ will be expanded to the URI-encoded language code matching the active MakeCode language.
Optionally, you can specify a localHostUrl
that will be used in local development mode.