Scripting Language Integration

Request new features or present your ideas.
Post Reply
User avatar
Ishq
Project Head
Posts: 1145
Joined: Tue Mar 06, 2012 8:32 pm UTC

Scripting Language Integration

Post by Ishq »

There have been various discussions about scripting languages on IRC in the past. This thread is to formalize a direction for scripting in Daemon and Unvanquished. Discuss below which scripting language you'd like and what you'd like to use scripting for and how it would be integrated.

My language of preference is JavaScript, the reasons for which will be explained below.

The primary use of scripting for me will be in the UI. The ability to implement the libRocket DOM in JavaScript will be a very straight forward task because the libRocket functions map almost one to one to the JavaScript DOM. Furthermore, as libRocket essentially implements HTML4 and CSS2, UI makers who are creating assets will already likely be familiar with javascript and be able to start working very quickly. The ability to use scripting will give rise to a much more dynamic UI with uses including manipulating the DOM, creating dynamic pages within the UI, firing and handling events, writing custom dataformatters, and if we wish it, animation. This is a project I would like to start sooner rather than later.

The other use for scripting would be scripted maps. This idea is less developed than the UI one above, but I still believe it is critical. The ability to be able to program things into your maps and have things be triggered can give rise to many things, from a tutorial engine to scripted single player maps. The tutorial engine is what I'm most interested for map scripting. I would like to allow any user to create interactive tutorials for use on any map that would help both new players and veterans alike. The scope of the tutorials can vary widely, from just the basics of wallwalking to more complex map level strategy discussions about scrim tactics. I have not thought extensively how this will be implemented, but I believe having scripting will simplify the process of implementing this.

To integrate JavaScript, I recommend using Tiny-JS. This is a tiny javascript interpreter that seems very easy to integrate into our engine. It is all together around 3.5k lines of code and has no external dependencies other than the standard C++ library. This sounds better than any of the more heavy alternatives like v8 or spidermonkey.

In summary:

JavaScript for libRocket and map scripting.

User avatar
Amanieu
Programmer
Posts: 44
Joined: Sun Jun 16, 2013 8:28 pm UTC

Re: Scripting Language Integration

Post by Amanieu »

I agree with the general idea of using scripts for maps and UI, but I disagree with the language choice. While I have no issue with javascript, I don't feel tiny-js is as well developed as lua for use as an embedded scripting language. For example, tiny-js doesn't implement all of the javascript language, and I'm afraid we might end up having to rely on sub-par technology (q3lcc anyone?).

I would also like to point out that we should not use scripts for any sort of advanced stuff, as this will only complicate the script API. See Tim Sweeney's post about why they decided to get rid of UnrealScript in UE4.

User avatar
Ishq
Project Head
Posts: 1145
Joined: Tue Mar 06, 2012 8:32 pm UTC

Re: Scripting Language Integration

Post by Ishq »

I too generally agree with Amanieu. I did more research on tiny-js and I also don't think it meets our requirements. Things like implementing arrays as linked lists and such. There is another (much larger) project called duktape. It can be integrated as a single file however. I think it's pretty cool.

User avatar
Viech
Project Head
Posts: 2139
Joined: Fri Aug 03, 2012 11:50 pm UTC
Location: Berlin

Re: Scripting Language Integration

Post by Viech »

I agree with Tim Sweeny (and I remember Carmack said something similiar with regards to idTech5) and I think for map scripting specifically, a NaCl virtual machine per map would be a more viable approach than maintaining a scripting API. If you want javascript as an extension/alternative for UI programming, fine with me.

Responsible for: Arch Linux package & torrent distribution, Parpax (map), Chameleon (map texture editor), Sloth (material file generator), gameplay design & programming, artistic direction

User avatar
Gireen
Graphic Designer
Posts: 295
Joined: Wed Mar 07, 2012 1:26 pm UTC
Clan: [DoH]
Location: Germany
Contact:

Re: Scripting Language Integration

Post by Gireen »

NaCl could allow it to make maps to small mods?
I think scripting api is a requirement for any singleplayer and tutorials.
Its easyer to use and wouldnt need much.
-react on events
-trigger events
-create objects(bots+buildings)
-give bots commands

for example with javascript

Code: Select all

game.on('startup', function(){
    var kills;
    bot = game.add('bot','human',position);
    bot.patrol([position, position, position]);
    bot.on('death',function(){
        kills++;
        if(kills >= 5){
              game.cp('good job');
              setTimeout( game.trigger('end','win','humans'), 3000);
        }
        else{
            this.say('again!')
            this.respawn();
        }
    });
});
User avatar
Ishq
Project Head
Posts: 1145
Joined: Tue Mar 06, 2012 8:32 pm UTC

Re: Scripting Language Integration

Post by Ishq »

I've decided on using http://duktape.org ( a js interpreter) because it's 1 file. Easy to integrate, and the designer seems to have taken deep thought on how to optimize it to the max without using a JIT. However, I have not gone too far with integration, so if anyone has any concerns at all, now is the time to voice them.

Post Reply