Hi, I was wondering if PlayCanvas has a module library equivalent? For example, on my server-side code, I can use a combination of module.exports and require to achieve pull functions and classes from one file into another, like so:
I spent a bit of time trying to figure out how to do this in PlayCanvas, as I know require() won’t work in-browser, but I kept getting stumped and eventually just made a blank entity object and attached the Lib script to it. This isn’t terribly ideal, as I wish I could keep non-editor data out of the editor.
Otherwise, the entity attachment method + some event handlers does seem to work, so at least that’s a relief. Otherwise just looking to organize my projects where possible.
I’m not sure I understand how this would work though. pc.app.root.findByName('Camera'); does indeed work, but it returns an entity component. Although if I understand this correctly, that was merely an example for how the PC app instance is global, which I do understand.
But if you have been doing web dev before the ES6 era, attaching a library to a global object is kind of normal.
Can you elaborate on this bit in particular? I’ve only picked up web dev recently, so I never encountered pre-ES6 functionalities. If it’s not too much trouble, what would an example ES5 library look like (as compared to the module.exports ES6 version? And how would you attach the library to a global object (which I can assume might be the Playcanvas object in this example)?