Libraries: JavaScript

Sora574
23 May 2013, 00:53
I know I've asked for a lot of things that libraries just can't accomplish in the current version... But I'm not done yet :lol:

Would it be possible to add a <javascript> tag into a library?
What I mean by this is... It's great that we can attach .js files to a Quest game, but it seems so old fashioned now, especially since HTML no longer needs to be inserted into the engine. I think it should be switched to being inside libraries instead of .js files.

Of course, then you would need to make the libraries editable in the Quest system, just like you can edit the JavaScript in the current version.

Or maybe, instead of completely getting rid of .js files, just add an additional option to add it into a library.

george
23 May 2013, 02:08
I've heard people talking about a javascript eval function. Could you explain to a novice why that doesn't do the job?

Sora574
23 May 2013, 02:36
george wrote:I've heard people talking about a javascript eval function. Could you explain to a novice why that doesn't do the job?

Gladly.

Basically, JS.eval takes a string and converts it into regular JavaScript.
Example:
JS.eval ("alert('Hello, world!')")

This would make a popup message saying 'Hello, world!'
However, if you wanted to do something more complex, like this for example:
function randomFunction(param1, param2) {
ASLEvent ("OutputText", "Param1: " + param1 + ", Param2: " + param2);
}
// This basically means that if you use the JavaScript function 'randomFunction("hello", "world")', Quest will print 'Param1: hello, Param2: world'

That wouldn't be possible in a library currently, as you would have to have a way to put it all into a string, but the only way to do that right now is to remove the line breaks. Imagine if you have a lot of line breaks though. That would take a while -- not to mention attempting to edit one huge line of JavaScript!
Of course, it is possible if you create a new object in the library and give it a JS attribute or something, but that's not very efficient.

Does that make any sense to you? :D

george
23 May 2013, 02:59
Yes, thanks for explaining!

Since I've been mostly using the GUI with code view I didn't think of code not in a Quest object :). But I can see now how this would be good for a library.

Sora574
23 May 2013, 03:29
Yes, it would also be a lot easier to release a library with JavaScript inside it than it would be to release a .zip folder with a bunch of .js files that you have to include as well as the library.