Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
So, i just wanted to try something. I tried to import a .js script into my main js file of my game so i can use the functions of it in my main js file. I used this: import * as Utils from "./scripts/utils.js"; My game folder structure: Game.exe Game.js scripts \ utils.js <--scripts is the folder of the utils.js But now when i try to run the game i get an error: SyntaxError: missing name in import statement. I dont know what the problem is, please help xD |
||||
|
hey agbdev, I believe CC only supports ES5, and that import is only valid in ES6 and above. I may be wrong, but I have tried all of the import statements I could find, and they all repeat the same error you have gotten. So no luck so far, but someone else may have an answer. Best of luck. |
||||
|
Hmm ok, but thanks for your answer :D I hope that if CopperCube only supports ES5, there will be an update for at some point. But somehow I find it funny that it doesn't say that import is not defined, right? Because if it is only supported from ES6 it would make no sense that you can write the keyword in ES5 then. That's weird xD Could be the CopperCube ES6 supports but that you simply can not use import. |
||||
|
To make matters even more confusing, the keywords const and let were introduced in ES6, but both work in CC. From what I have seen by looking through the forums, some other code introduced by ES6 also works. I also think the error for import is weird; hence why I assumed that it may be possible to use, but sadly nothing I tried worked. So maybe it's better to say CC is stuck in the middle of the two? Coming from a Python background, I too like to break my code into multiple docs for organization purposes. If i should happen to come across a solution, I will post my results here. |
||||
|
you can also use a function to read and pull in a js code file. I tried without success some code from haverbeke "Eloquent JavaScript 2" chap 10 Require function require() book is at archive org with a ton of other older JS books which is very useful because we need stuff that works in a JS5 engine |
||||
|
Good afternoon, I'm new to the forum, first of all I wanted to congratulate the developer and everyone involved in creating the engine. Being brief, I wanted to share a possible alternative to the issue of including / importing files in javascript: It basically consists of creating an Overlapping 2D object and all the js files that you want to use as inclusion add it to it as a "behavior" file; moreover, this object can be used as monitoring, for example: FPS count among other things. In this way, any function that returns a value, arrangement, whatever, can be called from other js files without problems, you just have to be careful in the names that are used. Also if I have not managed to make myself understood; sorry since my level of English is not good, I share a link with the scene in CopperCube: https://drive.google.com/drive/folders/10x8IuHq7EKSb6XX8XGPMBjGnnNoP1HEh?usp=sharing I hope it will be useful despite the time that has elapsed or to others who need it. Greetings to all. |
||||
|
@goro Thanks for your example! Here's a more recent post about the same issue: https://www.ambiera.com/forum.ph... |
|