Jump to content

Create and place objects in different files


skalibran
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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