Need Scripting

Discussion in 'Game Development (Technical)' started by ProgrammingFreak, Sep 26, 2007.

  1. ProgrammingFreak

    Original Member

    Joined:
    Oct 22, 2005
    Messages:
    126
    Likes Received:
    0
    Hi All,

    I was just wondering if your game really need's scripting? What are the benefits? Does it make it easier are there some things that you need with scripting to make a really good game.
     
  2. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Anything more complex than a match-3, tetris or other puzzle-like game can use scripting :). Of course it isn't needed, but it's more complex to write everything in C, C++, Java, Pascal or whatever language you use (unless you use a scripting language to make your game, of course).

    Easy modification without recompiles. If the system is designed cleverly you can add new stuff only by changing text files. Nikwi has this - only by changing a single text file you can add new entities or blocks and by writing extra scripts or modifying existing you can add or modify the behavior of all entities in there.

    Depending on the game, it can be a little easier or much easier. For example, i can live by writing a shooter in C (i've actually made one), but making something like an RPG or -gasp- adventure without a script it's like shooting yourself in the foot and then sinking it in salt.

    A good scripting language (like my UndeadScript :D) and knowledge how to script. I think there used to be a book on that, but ... it's possibly easier to check what others are doing. It's not rocket science and the web is filled with game scripts from people doing mods all the time.
     
  3. ZeHa

    Original Member

    Joined:
    Nov 19, 2006
    Messages:
    426
    Likes Received:
    0
    My current game engine is being developed in C++, but then will be compiled to a DLL and scripted using Python. So I'm not embedding scripts directly into the game, I do it the other way round.

    That's pretty cool actually, so the engine can do all the hardcore stuff like rendering, collision detecting and so on, but only knows an object class. Inside my Python scripts, I extend those object classes and then implement the real "gamey" stuff in there.
     
  4. Nikos Beck

    Nikos Beck New Member

    Joined:
    Jun 14, 2007
    Messages:
    321
    Likes Received:
    0
    Scripting doesn't require the engine to be rebuilt which saves a /lot/ of time. It also means that artists and designers, who aren't programmers, can tweak values on the fly. For example, the bounce of a soccer ball on grass as opposed to dirt.

    Torque Game Builder allows a game to be written entirely in script without modifying the engine.
     
  5. raigan

    Indie Author

    Joined:
    Jun 13, 2006
    Messages:
    49
    Likes Received:
    0
    That sounds pretty awesome -- do you know if the "embed the game inside python" approach works cross-platform?
     
  6. Paul-Jan

    Original Member

    Joined:
    May 30, 2006
    Messages:
    60
    Likes Received:
    0
    Nikos, or anyone else with positive experience with scripting, would you still advise to take the scripting route given that

    1) I'm a one man band as far as design and programming goes
    2) On a modern development machine rebuilding my engine takes < 1 second (I use Delphi, but for arguments' sake I could as well be using a interpreted or JIT language).
    3) I'm building my own "engine", so scripting support will take some work.
    4) The way I see it right now, my game does require some custom tweaking for most levels, but no extreme amounts of scripted events (just an action/puzzler with some level-specific behaviour).

    I ask this question, because I'm sure there are many developers in the same situation as me, and I'm not even remotely considering using scripting. Could be my lack of experience causing me to overlook the advantages (as well as increasing the investment needed to add support). For me, as a programmer, compilation time would be a major argument for scripting, but in this project that is simply is a non-issue. If I want to separate things from the core mechanic, might go for specification (xml, or something domain specific), but scripting... nah. Am I dead wrong?
     
  7. lennard

    Moderator Original Member Indie Author

    Joined:
    Jan 12, 2006
    Messages:
    2,390
    Likes Received:
    12
    Being able to change code and variables on the fly is a major advantage for me (I like to tweak while in the debugger) which is why I like VC++ 6.0 so much.

    For some reason VC++ 2005 (the successor) doesn't work nearly as well (and also breaks brief compatibility in new and wonderful ways) so I have gone back to 6.0. One advantage, for me, of having a single language is that there is less to consider when stuff breaks - I had a heinous bug in Real E$tate Empire related to Audiere last Spring - never happened here and tough to duplicate and pin down out in the field. Those situations make me want as simple of a code base as possible.
     
  8. zoombapup

    Moderator Original Member

    Joined:
    Nov 25, 2004
    Messages:
    2,890
    Likes Received:
    0
    For a small game, I'd probably go with an XML based config file.

    For a bigger game, I'd go with LUA

    I'm a long time torque engine user and I really like torquescript for what it does, but I think it has disadvantages as well, becuase people over-use scripts.

    Basically, I think scripts should be "configuration" and not logic. UNLESS, you are going to be releasing tools to the public, in which case, making logic in scripts is a useful feature.

    Its a design choice though, there is no right or wrong answer here.
     
  9. soniCron

    Indie Author

    Joined:
    May 4, 2005
    Messages:
    3,664
    Likes Received:
    0
    How about not even restarting your game to test changes? ;) If you use a purely dynamic scripting language (javascript, squirrel, lua, etc.), this is possible.

    I can make changes to logic, switch back to my game, and see the changes immediately. (It automatically refreshes the class structures upon detection of newly-modified script files.)

    I can't even begin to tell you how awesome this is when you're iteratively changing things, debugging, etc!
     
  10. ZeHa

    Original Member

    Joined:
    Nov 19, 2006
    Messages:
    426
    Likes Received:
    0
    Yes, you just have to write your C++ code cross-platform, and then compile it under Windows as a DLL and under Linux or Mac as a shared object file. Then you make a wrapper with SWIG or Boost::python. Since Python is cross-platform, too, there shouldn't be a problem :)
     
  11. Nikster

    Original Member

    Joined:
    Jul 27, 2004
    Messages:
    698
    Likes Received:
    0
    It depends on what you really need and what your application requires, some people will say, yay script, cool, just because it's script.

    I've used many different things depending on the application, I try not using a technology just for the sake of it, for example.

    We had an on screen editor for tweaking coefficients for car handling properties which was handy as you could do it all with a controller, pause, change, unpause, test..

    We use a markup language for static properties, level details, text layout, ini files and things that don't normally change but can be customised by anyone.

    Then we will use scripting if we need to dynamically control flow, have downloadable content within a game and depending on what we do in script, just save out the vm which is almost a free game save point.

    You just have to ask youself, is it really worth embedding script just to setup a few variables ?

    I suppose if you shed some more light on what kind of data you're wanting to parse might help more what people might suggest.
     
  12. ProgrammingFreak

    Original Member

    Joined:
    Oct 22, 2005
    Messages:
    126
    Likes Received:
    0
    Thanks for the tip guys. I was going to look into lua.
     
  13. BigBearScot

    BigBearScot New Member

    Joined:
    Sep 4, 2007
    Messages:
    1
    Likes Received:
    0
    To me scripting gives the benefits of not having to do a recompile if I change a small piece of game logic, for my last portfolio project I created a very simple 2D engine using C++ and SDL. I then exposed several functions and classes to Lua using Luabind.

    I now have a couple of Lua files which initialise the engine and then add sprites to a display list without touching the C++ code at all. I have used that engine to create a small breakout clone, it took about half the time to do it Lua than to do it in C++.
     
  14. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Although my opinion is somewhat biased, since i'm the developer of UndeadScript, i would recommend you to check other scripting languages than Lua. Except UndeadScript, of course, i recommend you to take a look in AngelScript, Squirrel, GameMonkeyScript and even Python and Scheme.

    Personally (and that's a personal opinion) i find Lua's syntax disgusting and i know at least two other programmers who are in the field of game development that share the same opinion :). Of course such things are totally up to the developer in question, so you should form an opinion by yourself. The best method, i believe, is to actually try some of these (most come with testing programs, suits, etc which you can play with - you don't have to actually embed them in your engine) instead of blindly choosing what others are choosing.

    I spend a lot of my game development time (both personal and for the company i work at) on scripting, so from my experience having a nicely designed language that you are comfortable with is a huge benefit :).

    </polite>

    And now that i closed that tag, i want to say that lua must face a horrible painful death :D :D :D
     
  15. ChrisP

    Indie Author

    Joined:
    Feb 5, 2007
    Messages:
    971
    Likes Received:
    0
    I think Lua is a brilliant little language - so "small" and yet so powerful! But yes, the syntax is heinously ugly. :)

    A scripting language can be useful in certain contexts, but a hindrance in others. It depends whether the time and complexity incurred by implementing the scripting language and giving it access to the functions it needs is worth the additional flexibility it gives you. Often it is, but sometimes it isn't.

    I once worked on a failed (personal) project that was going to use Lua scripting for everything and therefore be awesome (because scripting is automatically awesome in any context, right???), but it turned out to not be worth it. I eventually trashed the project in disgust at the amount of time it was taking. If I'd just written the darn thing entirely in C then it would have been finished in a fraction of the time and I could have got on with my life!

    As Nikster says, it all comes back to not using technology just because you can - you need a well-thought-out reason first. :)
     
  16. moose6912

    moose6912 New Member

    Joined:
    Jun 24, 2007
    Messages:
    219
    Likes Received:
    0
    Lua is actually pretty nice, I prefer Lua compared to Python anyway. The only thing that I cannot seem to get the hang of is that index starts at 1 for tables, not 0 which is the standard for C++, Java, VB etc.
     
  17. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Doesn't VB provide OPTION BASE anymore? :)
     
  18. moose6912

    moose6912 New Member

    Joined:
    Jun 24, 2007
    Messages:
    219
    Likes Received:
    0
    Yup,i forgot about that since I have never used it before.
     
  19. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    Well i think that starting from 1 is a more natural thing for most people :). I remember when i was learning C, with many years of Pascal experience in my back, i was frustrated with arrays beginning from 0 :) because in Pascal you can define your own range and i always was using "array [1..100] of Integer;" instead of "array [0..99] of Integer;". Nobody told me to start from 1, i just did so :).
     
  20. DavidL

    Original Member

    Joined:
    Feb 6, 2005
    Messages:
    21
    Likes Received:
    0
    One other advantage that many scripting languages, such as Lua, provide is the ability to setup coroutines, which are a bit like threads, but are cooperatively multitasked. Each coroutine has the ability to pause itself, with some higher-level piece of code telling it when it can resume.

    Such a feature can be particularly useful when writing animations or AI. Take the following bit of Lua code as an example:

    Code:
    -- Move a sprite 100 pixels up over the span of 500 milliseconds.  Wait before continuing.
    SlideByOffset(mySprite, {0, -100}, 500)
    WaitForAnimations(mySprite)
    
    -- Fade alpha to zero over the span of 250 milliseconds.
    Fade(mySprite, 0, 250)
    WaitForAnimations(mySprite)
    
    -- Destroy the sprite
    Kill(mySprite)
    
    In this example, WaitForAnimations() pauses the execution of the script until all animations (slides, fades, etc.) are complete.

    Doing something like this in C++ is possible, but generally more difficult to pull off.
     

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