MackeyK24 Posted November 2, 2016 Share Posted November 2, 2016 Are there any facilities to dynamically load javascript in babylon js... If not what it the recommended way to load javascript from a string? Is window.eval ok to use in a custom scene loader (like objFileLoader.ts)? If i use window.eval to dynamically load javascript, will it be acceptable code to submit to github project? Quote Link to comment Share on other sites More sharing options...
joshcamas Posted November 2, 2016 Share Posted November 2, 2016 jQuery has the ability built in: jQuery.getScript() Alternatively you can just load the file however you want (with the fileloader.ts, or any other way) and then run eval(). I *think* that's the only way to evaluate js. Quote Link to comment Share on other sites More sharing options...
JohnK Posted November 2, 2016 Share Posted November 2, 2016 How about this var url = "http://PATH/myFile.js"; var s = document.createElement("script"); s.src = url; document.head.appendChild(s); s.onload = function () { //Use the script now } Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted November 2, 2016 Author Share Posted November 2, 2016 I need to dynamically load script i already have in a string... just winding if the babylon folks would DISALLOW any code with 'eval' or if that is ok... I hope it is... because is seems like the only way to 'eval' string script Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 3, 2016 Share Posted November 3, 2016 What do you want to PR? can you describe the code? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 4, 2016 Share Posted November 4, 2016 PR = "pull request", MackeyK24 (in case you didn't know). It is the approved way to contribute to BabylonJS framework source @ GitHub. Were you talking about contributing to BabylonJS framework... via GitHub pull request? That is why Deltakosh is asking this. IF you were referring-to submitting a project... to YOUR GitHub repository, then no problems... use eval in your projects, if you please. But it is wise to learn about the potential hazards of using eval. I just wanted to clarify a possible mis-understanding. No 'eval rules' for your own GitHub-based project. Possibly SOME 'eval rules' for contributions to Babylon.js core. Ok bye. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
royibernthal Posted November 4, 2016 Share Posted November 4, 2016 I believe he meant contributing to the bjs repo in case it doesn't already have built in js loading functionality. Mackey why would you need to use eval? Basically it should be avoided whenever possible, it's best practice to not ever use it, especially not in an open source project used by many people. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 6, 2016 Share Posted November 6, 2016 *nod* I'm no client-server guy, but... let's pretend the server needed to change a "world" weather condition... for all listening clients. There's really 2 ways to handle this. 1. Put a weather-changer function in everyone's client JS (at auth-in/initial-client-load)... and then when it's time to make it rain, send a packet (a weather-change packet-type?) to all clients... saying WHICH function to run (if it is not already TYPED as a weather change packet type), and include the needed data FOR that function... to make it rain. In other words, send data for the already-onboard weather changer function. 2. Send the entire make-it-rain function, in a packet... to all clients, and then "order" all clients to execute the arriving function... via eval. This is where I would use eval... if I were me. Client-side packet-handling would be very simple, this way. Unpack the packet, and execute whatever JS was found within. But I'm just speculating. It's not about me. Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted November 6, 2016 Author Share Posted November 6, 2016 Nevermind... I just gonna pull that little feature from the Unity Exporter/Editor plugin If i anna dynamic load from string... i have had success creating var s = document.createElement('script'); s.async = false; s.textContent = "javascript code"; so far that works load javascript from a string 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.