sinisterchipmunk / jax

Framework for creating rich WebGL-enabled applications using JavaScript and Ruby
http://jaxgl.com
MIT License
96 stars 16 forks source link

todo: dynamically code editing #4

Open brownman opened 13 years ago

brownman commented 13 years ago

is it possible to change+reload some mvc part of the code?

my suggestion includes an option to make this framework more scriptable.

sinisterchipmunk commented 13 years ago

As of last night, Jax controllers support an update() function. (I haven't yet committed the code though, so expect it within another 24 hours or so.) If you define this function, it will be called automatically periodically, and it will be passed a timechange argument representing the number of seconds passed since the last update. You could use this to calculate AI, move a space ship, operate a combat system, and other off-screen logic. I don't think this addresses the idea of a scripting language, however, so let's talk about that:

Javascript is by its very nature dynamic. You should be able to execute custom code on the fly by simply passing it into eval(). This is also very unsafe, however, unless the code has first been sanitized. Otherwise a malicious user could hijack the game, especially if you save the script anywhere (such as for use in multiplayer). So, a domain-specific language (DSL, or scripting language) would have to be written. It would be interesting indeed for Jax to support such a DSL out of the box, but I'm not convinced of the viability. Jax has no up-front knowledge of the structure of your game (is it a flight simulator? first person shooter? RPG?), so I don't know if we can expect it to be able to manipulate it very effectively.

On the other hand, it could possibly provide a very limited scripting language that could, for example, redirect to other controllers, add instances of models to the world, add particle systems, etc.; and also provide "hooks" for the developer to add their own scripting commands (such as stopEngines() or reloadAmmo()).

It's an interesting idea in any case, but a very long-term improvement and certainly not something I'll add before the first official release. I'll leave this ticket open as a reminder, and if anyone else wants to take a shot at implementing this, they're more than welcome to do so.