Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Using Coffeescript compiled to Javascript for Coppercube - will it work?

blackwater
Registered User
Quote
2023-11-21 15:20:50

I'm an artist. Maths and coding is not my thing. I've never really understood the structure of coding and not for lack of trying. The threshold always too high for me to pass. And when trying my very best, my "coding" is like that of a dyslectic, constantly "spelling" the code incorrectly.

But today, i found out about Coffeescript https://coffeescript.org
And i feel like, wow, I can understand this!

So, this could work for use with Coppercube, right? (compiled into Javascript). Or will it translate some of it into a "new" javascript-version that Coppercube won't digest? As one example i found: When writing == in Coffeescript, it seems to be translated into === when compiled to Javascript - an example that will not work, or?


okeoke
Registered User
Quote
2023-11-21 16:17:03

Hi blackwater,
Answer is both yes and no:)

You can fully use it if you target webgl, but using it for desktop is questionable.

Modern coffeescript translates to es6 javascript, which is not supported by CopperCube. Coppercube only supports es1 or es3 version. If you avoid using modern features in your script you probably can code with it. At some point your code might be translated to js which utilizes es5+ features, and it will stop working. The issue is that you don't have any control over this translation process. So if compiler decides to use es5+ syntax it will do that, and you can't do anything about that.

You can also try old coffeescript version which I believe translates to es5, which is much closer to the version we have in coppercube. Or try using babel to translate es6 code to es5. I don't really think the last one will work.

Overall, usecase is the following.
1. Install coffeescript globably, as the site you provided says.
2. Create new coppercube file
3. Create another file named the same, as just created .ccb file but set its extension to ".coffee". so if coppercube file is demo.ccb, new file name should be "demo.coffee"
4. Add your script demo.coffee file, like
someVariable = 'hello from coffeescript'
print(someVariable)

5. Compile to js using command line: coffee -c demo.coffee. This will create another file with .js extension like:
// Generated by CoffeeScript 2.7.0
(function() {
var someVariable;

someVariable = 'hello from coffeescript';

print(someVariable);

}).call(this);

6. Build and run coppercube game from the editor
7. You should see "hello from coffeescript" message printed out.

Demo:https://drive.google.com/file/d/...


blackwater
Registered User
Quote
2023-11-22 14:18:29

Thanks for claryfing!


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Int?rnational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact