skalibran Posted August 27, 2015 Share Posted August 27, 2015 Hey there, for the first real project, I want to outsource as much as possible. In the index-File, I just want to combine everything. For example I want the creation of all objects in another javascript file, and I want to call it using a function in the index file. The problem: Whenever I want to use a created object, it does not exist because it was made in another javascript file. Is there a way to create real global variables that are valid for the whole session? Or is there another way to outsource all the javascripts? Thanks! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted August 27, 2015 Share Posted August 27, 2015 If this 'index-File' is just a bunch of global unassigned reference variables, could you not just list it as the first application level script tag in the header section? If that did not work, or you wish to be different for deployment, you could keep all your files separate, then have a tiny build script. Could be as simple as a one line .bat, or .sh, using copy or cp. Once you have all your application level code in one file, you could also use one of the online uglifiers for extra deployment effeciency. A quick test without real code, should confirm whether there would a a problem. I plan to break things up as well using .ts files, then combine as part of my build, but do not plan to have such a file. An OO approach would be to create subclasses of mesh with all the extra stuff they need. This extra stuff would be both in the file & in the class. Any references to instances of a class in another file could be passed as arguments, derived from a scene lookup call, scene.getSkeletonByID. Quote Link to comment Share on other sites More sharing options...
skalibran Posted August 27, 2015 Author Share Posted August 27, 2015 Hey, thanks for the answer! I'm probably not deep enough in javascript, what do you mean with "first application level script tag"? Seems like an uncomplicated first try. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted August 27, 2015 Share Posted August 27, 2015 In the head section of your html, use must specify your .js fles. The order is important. You put stuff that other files reference first. Like babylon.js. Quote Link to comment Share on other sites More sharing options...
skalibran Posted August 27, 2015 Author Share Posted August 27, 2015 Hey, I just have one other js-File right now. If I - for example - create a cube in-code inside the main index file, the problem is that I cannot modify its height or width in another file because that file does not now the cube. Of course I could write the parameter inside the function, but if I have - let's say 300 elements - I cannot write all those things into the function (otherwise it would look like function(var1, var2, var3, ..., var300)). Later on, I want to create that cube in a javascript file that exists just for creating elements on startup, then load it into the index-file and modify its values inside another file. 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.