AngelScript vs Lua

Discussion in 'Game Development (Technical)' started by Pogacha, Sep 16, 2009.

  1. Pogacha

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    605
    Likes Received:
    0
    Hi!
    I need to add scripting language support for my engine to speed up the development processes ...
    After reading tons of opinions, benchmarks and discussions I'm picking ActionScript because of:
    - It is easy to embed.
    - It is similar to C++
    * So it is easier to me to learn to program it.
    * If some code turns heavy you can move it to the native core without many problems.
    - It is statically typed (thing I prefer with all my heart)
    - Unicode support and multiplatform.

    The cons are:
    - It is not Lua, which is faster, more used and maybe more stable.

    But my question is for the ones who knows both systems ...

    Is there another very important thing to have into account to chose one of them?
    Is there any limitation that may be crucial for a development that one has and not the other?
    Any other recommendation before jumping in?

    PS: I don't care about the byte code precompilation ...

    Thanks in advance!
     
  2. Pallav Nawani

    Indie Author

    Joined:
    Aug 13, 2004
    Messages:
    371
    Likes Received:
    0
    Here is the reason I decided not to use angelscript:
    If you want do things like creating an C++ object in angelscript, you will need to carefully manage memory. Since angelscript is built to interface with c++ directly, the question arises as to who manages the allocated memory: your c++ code, or Angelscript.

    If I recall correctly, this forced you to implement some kind of refcounting for all your objects, and I didn't want to touch my old code.

    I strongly suggest you use lua instead.
     
  3. luggage

    Moderator Original Member Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    I'd sit down and think if adding a scripting language really will make development go faster. The big questions is...

    Who's writing the scripts?

    If it's other non-coders, then it's worthwhile.
    If it's going to be you, then I'm not so sure.
     
  4. Emmanuel

    Moderator Original Member

    Joined:
    Nov 23, 2004
    Messages:
    859
    Likes Received:
    0
    A scripting language won't speed up your development process if you're writing all the logic yourself, it will slow it down. Embedding the language, adding bindings and whatnot, makes it very easy to get lost in the technology thinking you're getting work done. Also, more importantly, debugging a script isn't anything like setting a breakpoint in visual studio and seeing the whole stack from logic to engine.

    This said, it's quite useful for setting some arbitrary values and hitting a key to reload, when you're finetuning things, although simple ini-like files can do that too.

    I have no experience with angelscript. Lua is quite easy to embed, and bindings can be done rather quickly with Swig (or luabind, if you like pain). Python is also quite nice, not as fast to interpret as lua but much less error prone, the interpreter is a lot less whacky and there are tons of libraries for it to do just about everything.

    Best regards,
    Emmanuel
     
  5. Gary Preston

    Original Member

    Joined:
    Aug 5, 2005
    Messages:
    239
    Likes Received:
    0
    I disagree (although depending upon the scale of the game project I may also agree :D )

    On a number of projects I've worked on, the ability to use a scripting language for various parts of the game logic has saved numerous hours of development time. Especially during the earlier "prototype" stages of development.

    Non-Coders would be better served by a decent set of tools to edit game information than a scripting language.

    The caveat to both the above statements though, is project scale. If the game is small in scope, then the time spent integrating a scripting system or developing tools may not actually pay off. For larger projects though, script pays of very quickly in my experience as do tools. In both cases you can get a secondary pay-off after shipping as script can make your game easier to mod (likewise for tools)

    I'd also reconsider the strongly typed scripting requirement. That's a more useful requirement for a core programming language, but for scripting there are many instances where a dynamically typed language can pay off.
     
    #5 Gary Preston, Sep 17, 2009
    Last edited: Sep 17, 2009
  6. Pogacha

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    605
    Likes Received:
    0
    Thanks so much for your honest answers.

    The reason I want to implement scripting is the scale of the project, I never need scripting before.

    We detected a bottleneck in adding content and basically it is because the time from coding to actually test it. Edit and continue doesn't work to add new content. So adding and testing content at the fly where more than initialization vars are needed (for example a little IA) would speed up the processes without a doubt.
    As well we already implemented a console to interact with the game but some times we would prefer it to be more than an access to vars and functions. This is mostly the case on the editors and tools, some times you just need an special action to be done (rename all the animations starting with L) or insert a pause in one animation and actually having to save all, close the app, modify it, recompile it, and restart it, reload to be were you left takes its time.
    As well we have an expression interpreter for NPCs, which compile the expressions to bytecode, but the way to go would have been to use an scripting language for them.

    This is something I will have to be aware of ... we will have to balance this in a sensitive way.
    The idea is to invest more time in the technology to allow creating a game as a mod so it can be done by other people in my team without having to deal with the core code itself, just "adding content".

    I guess this statement is true for both Lua and AngelScript ... also I'm sure a refcounting can be added with a wrapper template class. I will take a deeper look at this, thanks!

    We find AngelScript easier to integrate given our engine structure, we saw luabind but when we read the word "Boost" it was the end of the story for us ... I didn't know about Swig I'm reading it.

    I can't stand it ... the only situation I can think is when you cast numbers to string and the opposite ... but I don't see the big deal ... my view is so limited in this aspect since I have no experience, my original question is related exactly to that. Where is the power of a dynamically typed language?
     
  7. Gary Preston

    Original Member

    Joined:
    Aug 5, 2005
    Messages:
    239
    Likes Received:
    0
    It comes down to productivity and I have to admit although I firmly believe there's a big productivity gain to be had from dynamic scripting languages, I'm struggling to actually provide some concrete examples for you. So I'll present you with some "fuzzy" advantages :)

    You can write less verbose code. Which brings with it a "freedom" to just write code without an excess of structure. That might sound like a dangerous thing compared to a heavily typed language, but when scripting, the extra freedom often results in a productivity gain, especially when prototyping.

    Another advantage is the ability to modify just about anything at run-time on the fly. You can also use "eval" style functions, although these can often be abused it can be useful in some cases.

    Perhaps it's one of those benefits where to appreciate it, you really have to just bite the bullet and use a dynamic language for a while and then consider how it has altered the way in and speed of which you code compared to the previous strongly typed language. As with the choice of engine language, it's likely a matter of personal taste.
     
  8. Pallav Nawani

    Indie Author

    Joined:
    Aug 13, 2004
    Messages:
    371
    Likes Received:
    0
    No, because you can't directly exchange data between Lua & C++. You need to pass it on the stack & so forth. There is a fundamental design difference between Lua & Angelscript.

    About boost. Luabind uses certain boost headers, but you don't need to understand it to use it. I don't either. Just extract boost somewhere and in your luabind project set the path to the include files and you're done.

    It took me around 4 days to integrate lua & luabind when I did it the first time. Mostly because I was doing it for the first time and wasn't sure what to do.

    I still suggest you use Lua.
     
  9. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    I usually roll my own scripting engines (i've done so many i can write a C-like interpreter in a weekend :p). However if i ever was going (=forced violently) to use a 3rd party scripting engine, that probably would be Python. While its on the "big" side, its the only scripting language that somehow managed to make me like it a bit, even if that took a couple of years (and a need to write a bunch of Blender addons :p).
     
  10. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    Just thought I'd jump in and suggest googles V8 javascript engine as a possible too.

    Its undoubtedly going to get a lot of development in comparison to something like angelscript and the like. I havent used it yet myself, but have seen a few other game devs using it.

    They have examples of using it with C++ code, which is what it does in webkit if I am reading it right.
     
  11. jcottier

    jcottier New Member

    Joined:
    Jul 12, 2006
    Messages:
    1,385
    Likes Received:
    0
    It's been many years since I moved to the next step: coding your game with graphical tools. Obviously, this make sense if your game is content heavy. I made my first tool like that when I was working on "The Movies" a AAA game with a HUGE amount of content. It's just amazing how much time were saved.

    I recently created a simple one for my latest game: a point & click adventure with many puzzle mini games. I create the mini games with c++ but the entire game adventure is "coded" with the graphical tool. I can create everything in this tool: logic/animation/painting the selection area/adding sound. What ever I want really. Once you realize how basic most game logic are, it just doesn't make sense to create them with something as complex as c++ or lua. A more special tool will make your life many time easier.

    JC

    [​IMG]
     
  12. MFS

    MFS New Member

    Joined:
    Feb 28, 2007
    Messages:
    314
    Likes Received:
    0
    That sir, is interesting. I'm so/so on scripting languages; used them before, acknowledge where they save time, yadda yadda -- but using a UML designer (essentially) to make a game is pretty nifty. I've seen similar, but nothing that was ever actually used to produce content of scope like you are referencing. Neat :)

    The magic numbers look somewhat bitchy to track though -- why numbers instead of something more descriptive...like a name?
     
  13. Mattias Gustavsson

    Original Member

    Joined:
    Aug 10, 2005
    Messages:
    669
    Likes Received:
    0
    In general, I think it is a little bit dangerous to think that way. In the long run, and especially during the later stages of development, when you're finishing things off and making sure everything works everywhere, chances are that you're going to be looking at any area of the code - even at third-party libs - to figure out why some things doesn't work. Saying that you don't need to understand everything you use is rarely true - at some point you WILL have to understand it on some level, and that is a good reason to try and use as little extra code as possible. Some people (me included) see code not as an asset, but as a liability - not a bad way to look at it.

    When it comes to scripting in general, I think that if your goal is making a game (rather than just generic technology, which I know some people like to do for the fun of it), you should add a custom made scripting language or none at all. A custom made one, be it visual or text based, which is tailored specifically to the tasks at hand, will certainly help with content creation. And it doesn't have to let you do *everything* - it's ok to have to add new supporting code every now and then. A generic scripting language will be harder to use and debug than C++ through the IDE, and progammers generally hate having to use more primitive tools than they have to (especially if the only benefit is that they don't have to recompile - it's generally not a big deal for programmers to have to do recompiles).
     
  14. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    I'm not sure I agree with you there. Lua has some pretty good debuggers after all.

    I'm not interested in writing scripting languages. On the flipside, many scripting languages are just really bad at binding to C++ (I'm looking at you lua!!)

    Main things for me is easy C++ integration, reasonable performance, good documentation/syntax and a usable/stable debugger! Not much to ask you would think :)
     
  15. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Regarding bindings, UndeadScript (probably the most advanced scripting language i've made, although it has been a while since i touched that code -- writing it in C++ was a bad choice and if i ever work on it again i'll probably convert it to plain C) uses a "register function" call to register a native function that gets a VM instance from where it will get arguments and return stuff. AFAIK this is the most common method to implement native functions.

    However its also very tedious, so i wrote an "interface language" which is basically a subset of UnreadScript: definitions without the code. The interface language interpreter parses the interface code and creates code for the host program (supporting C++ and FreePascal targets). This sped up the development a bit, but at some point when i was working at Track7 Games (where we would use UndeadScript for the game), i realized that i'm just rewriting the same stuff in C++ and the interface language.

    So i just wrote Yet Another Interpreter* that parses (our) C++ headers and creates code in the interface language (i could make it spit out C++ code directly, but writing IL code was much easier :p). I added that in our building tool and from that point on i never had to write any interface code.

    So in short, if you find yourself writing a lot of interface code for a scripting language, just automate it.

    (*=i think its becoming obvious that i like this sort of stuff)
     
  16. xelanoimis

    Original Member

    Joined:
    Apr 25, 2005
    Messages:
    126
    Likes Received:
    0
    Since everyone is giving advice on scripting here, let me add a few lines too (in fact quite a long post - sorry):

    --------

    I vote for having your own scripting language if possible. That is if it's not something too complex - I wouldn't advice anyone to build another Python. And if you need something more than just ini files.

    I worked with Lua and I very much like it exept 2 things: the non-C syntax and the fact that I was having no idea what it does behind my back - I do now ;) I hate its indexes start from 1 not from 0 and once I struggled to find out why -2 is bigger than -1, to finally discover they were strings... :p

    Lua 5 is fast. Really fast. Mainly because its virtual machine uses registers instead of a stack, and because it has a single numeric type.

    A worthy alternative to Lua might be Game Monkey. That is very similar in construction and it has a C like syntax. In my benchmarks, Game Monkey is usually as fast as Lua4, maybe faster in some tests.

    All these, Lua5, Lua4 and GameMonkey have enough speed to run in a game per frame (if you don't use them badly).

    --------

    I use my own script, called GS9. Like GameMonkey, it was build based on the good things I like in Lua, having a C-like syntax. The first edition (in fact v2.) is used with success in my DizzyAGE engine (see my signature).

    Recently I did some optimizations for speed and memory when dealing with strings and tables. And to add some integration for game objects access. And it turned out quite nice. It's comparable in speed with Lua4 and GameMonkey, which as I said is more than enough.

    GS9 is free to use and you download the sources here: www.simion.co.uk/gs9

    --------

    Also consider precompiled scripts (in binary format) because they load very fast - especially if your game have lots of scripting.

    And a very useful feature is having "latent" scripts support. That is being able to stop the script execution at one point and continue it from there in the next game loop. This allows you do things like WaitSeconds(5); PlayAnim(); WaitForAnim(); choice=ShowChoiceMessage(); etc. And you'll be able to run one or more scripts "in parallel", like for entities AI. I you don't have this feature, you must implement a system of callbacks and specify the function to be called after a certain action (like PlayAnim) ends. This is much harder to follow and debug.

    --------

    If I didn't have my own script (and not wanted to write one), I would definitely use Lua because of it's popularity. I don't trust any complex bindings with C/C++, especially if you plan to make something portable. And in most cases you don't need to implement classes in your script - that's taking a lot of knowledge and can be more than a simple game needs.
     
  17. Pallav Nawani

    Indie Author

    Joined:
    Aug 13, 2004
    Messages:
    371
    Likes Received:
    0
    You will have to draw a line somewhere. Every game depends on a lot of code that is not written by the developer - Os, DirectX runtimes, graphics card drivers. If you insist on understanding everything, you will spend a incredible amount of time not making a game. Sometimes its just better to use off the shelf software - especially if it is high quality like boost & luabind.
    I suppose it is all about priorites. I like to get on with the business of making a game.
     
  18. Mattias Gustavsson

    Original Member

    Joined:
    Aug 10, 2005
    Messages:
    669
    Likes Received:
    0
    We all do, and there's different ways to go about it. All I'm saying is that for me, it makes sense to avoid dependencies when possible, as it lets me "get on with things" with less problems in the long run. If I'm looking at a small benefit for a huge dependency, it might not be worth it. If it's a big benefit for a huge dependency, it would probably be worth it.
     
  19. Pogacha

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    605
    Likes Received:
    0
    I know if the objective were to have the best script language that satisfies my own needs the best option would be to write my own, but the objective is to speed up the development process. Unfortunatelly, those objectives aren't congruent, It would take me up to a month to write something as tunned as AngelScript, so the bet expecting it to pay off in the long run would be too high.

    I'm limited by time also so I cannot spend 4 weeks getting experience with different scripts to then decide which one should I use or how would I like mine to be written, which would be the professional way of taking this kind of desission.
    So far I haven't found a strict reason to not try AngelScript. I won't implement it right now but in the near future. I want my mind to revise this subject for enough time.

    Thanks again :)
     
  20. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Actually if you really had to choose between Lua and AngelScript, then i believe that AS is the better choice :).

    @Mattias Gustavsson:
    I agree with that. I try to avoid dependencies as much as possible.

    Although it has been more than three years since my last desktop game and since then i've made only a few Flash games. I think that if i had Pallav Nawani's mindset i would have more games finished.

    Thankfully i actually like what i'm doing :)
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer