Solved:
Solution
I updated C3 to the most recent version, and the Platform Info script interface now works as expected.
Problem
Without realizing it, I had been using an outdated version of C3, that predated the addition of the Platform Info script interface.
Cause
It was me all along! My C3 version was out of date as a result of my having left the same C3 Chrome tab open across several days. Without refreshing the tab, the version fell behind. I'd updated the C3 version in an adjacent tab at some point, and didn't realize later on that I then had multiple C3 tabs open that were running different versions.
Original post:
I'm trying to use the "Platform Info" script interface to determine if my project is running in a browser, or in NW.js.
I can't seem to access or interact with the platform info script interface at all.
I assume I'm doing something wrong, but I'm not sure what.
What I tried
I initially just wanted to test out printing the platform info's os value to verify that I could.
1. I created a new empty project.
2. In the layout editor I right clicked to insert a new object, and chose the "Platform Info" object.
So, in the project bar, in the "Object types" folder, there is now an object named "PlatformInfo".
3. In the "Scripts" folder, I double-clicked "main.js" to open it in a tab.
4. In the main.js tab, in the function body for
async function OnBeforeProjectStart(runtime){}
(edit: Following R0J0Hound's reply below, I should also mention I've also done all of these tests from within the Tick() function as well, just to be sure that pretty much everything would get a chance to load.)
I added the following five console.log statements to the top of the function body. Each line is just trying a different way to access the platform info data.
console.log( runtime.platformInfo );
console.log( runtime.objects.PlatformInfo.getFirstInstance() );
console.log( runtime.objects.PlatformInfo.getFirstInstance().os );
console.log( runtime.objects.PlatformInfo );
console.log( runtime.objects.PlatformInfo.os );
5. I ran the project in preview mode, in Chrome, and when checking the Chrome dev tools, I got the following output in the console:
// undefined
// [object Object]
// undefined
// [object Object]
// undefined
For clarity, here are the expressions and their output shown together:
runtime.platformInfo
// undefined
runtime.objects.PlatformInfo.getFirstInstance()
// [object Object]
runtime.objects.PlatformInfo.getFirstInstance().os
// undefined
runtime.objects.PlatformInfo
// [object Object]
runtime.objects.PlatformInfo.os
// undefined
Chrome dev tools
To better understand what I was looking at, I used a break point in Chrome dev tools to pause execution of the preview. I set the break point at the end of the function body for
async function OnBeforeProjectStart(runtime){}
and with the execution paused, I inspected the "runtime" variable to see if I could find
"runtime.platformInfo", but I wasn't able to.
I was looking for this property on runtime because I thought the Platform Info script interface documentation was explaining in the second paragraph that it is the preferred way to interact with the platform info features.
So, I'm pretty sure I'm just missing something pretty obvious, but I'm not sure where I've diverged from what I'm supposed to be doing.