Jump to content

canvasplus wich version of javascript is supported ?


espace
 Share

Recommended Posts

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...

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...