espace Posted November 3, 2017 Share Posted November 3, 2017 Hi, I don't find the information on the net so : wich version of javascript(ES5, ES6 ???) is supported trough canvasplus on cocoon.io ? by test i know that these snippets are not supported when i launch my game on canvas+ : var myFunc=()=>{}; let variable; const anothervariable; Could you tell me more about that... Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 3, 2017 Share Posted November 3, 2017 Good question, I could find nothing in their docs that suggests JS language feature support. I'm guessing its basically ES5 compliant, so treat it like any other old browser and transpile your stuff back before running it in canvas+. Quote Link to comment Share on other sites More sharing options...
icp Posted November 3, 2017 Share Posted November 3, 2017 You can add this plugin https://github.com/vstirbu/PromisesPlugin or get any es6 polyfill. Quote Link to comment Share on other sites More sharing options...
espace Posted November 6, 2017 Author Share Posted November 6, 2017 hey guys, finally i have discover what don't work in my game this snippet is unsupported by canvas+, it's on the doc => webworker. guit.parameter.onChange(function(value){ args[0].fire(); logic_position(args[0]); }); thanks also to icp for your plugin it works. A simple question is there a way to maintain this code on my main.js and by a way when on canvas+ disable this snippet to avoid black screen ? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 6, 2017 Share Posted November 6, 2017 With canvas+ you specify the index.html right? Which might be different than the one you would use to push it to a url, for example. So, the absolute simplest way is to just add a global to the page for the canvas+ implementation: <script> window.isCanvasPlus = true </script> Then in your code just use an if to check for this variable: if (window.isCanvasPlus) { // run canvas+ code } As JS is permissive about variable types the above will continue to work as isCanvasPlus undefined will be falsy. Quote Link to comment Share on other sites More sharing options...
espace Posted November 6, 2017 Author Share Posted November 6, 2017 hi mattstyles, when canvasplus read the index.html if in the src tag there is a file with syntax problem (eg: let value="hi") cocoon crash. So i imagine a thing like this, but unfortunately that don't work <script window.isCanvasPlus = true></script> <script !window.isCanvasPlus && src="src/webview_main.js"></script> <script window.isCanvasPlus && src="src/canvas_main.js"></script> have you a better idea ? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 6, 2017 Share Posted November 6, 2017 oh, ok, you can conditionally add a script tag later (which is how many analytics or font loaders work), something like this should work: var script = document.createElement('script') script.src = 'src/main.js' document.body.appendChild(script) You have to append it to and let the browser load it normally, technically you could grab the text and eval it but you don't want to do that! Just add the script tag and let the browser work as normal. You don't need the global flag either with this method, you just whack in script:src='main.js' if you host it outside of canvas+, and use the small script above to add scripts to the page when you are in canvas+ land. If you have a couple of files just extract that script above into a function that accepts the src/main.js and creates and appends those scripts for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.