Sign in to follow this  
THACO

Scripting

Recommended Posts

Ok, I decided I need scripting support, something somewhat simple. My game is like a 2d side scroller. Most characters have the same basic attacks, some sorta of attack forward, up down, etc. The trick comes in their special moves usually 3 each. I want to be able to script them and not hard code them for each character. I have never really done much in scripting before. I figure I would have a text file and just read in and depending on what is at each line take it in. Sample line might be "functionA 5 .25 " this would mean call functionA with parameters of 5 and .25. Its not groundbreaking, I assume it should work for how I need it. Should I also try to expand it for AI needs, and be able to create the script on the fly? I am just trying to think a head because I want this to be easy to modify, because I have around 8 characters and dont't want to hardcode and shouldn't hardcode each characters special powers -THACO

Share this post


Link to post
Share on other sites
I would recommend going with an existing scripting system like Python or Lua instead of trying to roll your own. Especially if you don't have much experience with scripting.

Share this post


Link to post
Share on other sites
That seems to way over the top maybe? For AI I can see the need. For now I just need some way to create and use special moves without hard coding them. By creating a few built in functions then using a file to say which ones are called and in what order to actually complete the move. Learning Lua and interface with C++ seems like it would just be so much extra. I will do some more looking into it. You are a mod for a reason, and I do not know much about scripting especially when it comes to how it should work with games.

-THACO

Share this post


Link to post
Share on other sites
If you use something like LuaBind or ToLua++, the amount of work involved in binding is really rather low. More importantly, you will spend much, much less time going back and adding functionality to your scripting layer.

Share this post


Link to post
Share on other sites
I'll third the suggestion for using an existing implemention such as Lua. It would be over the top to waste a whole bunch of time writing your own lexer, parser, etc... when such things have already been written (and debugged, and thoroughly tested) for you. It's better to go with something that is already done and that has too much power for your (predicted) needs, than to roll your own that is buggy, slow, takes years to develop, and ends up being too limited for something you want to do later on down the road. This is coming from somebody who made the same mistake several years ago, before switching to Lua. [grin]

Share this post


Link to post
Share on other sites
well it seems the mods have it, so ill go in that direction, thanks for all the advice

-THACO

Share this post


Link to post
Share on other sites
If you don't want to use an existing, full-blown scripting language and you don't want to write your own lexer\parser from scratch, you might want to look into YACC and Lex. I'm fairly sure there are Windows ports available.

Share this post


Link to post
Share on other sites
Yacc and lex are far from intuitive unless you have a decent knowledge of language grammar and compiler design. In effect, it's the same as rolling your own - you're just expressing it in BNF rather than C.

Share this post


Link to post
Share on other sites
If you decide to go the Lua route, here's a tutorial at gamedev called An Introduction to Lua.

You'll also want to look at this thread discussing the article.

Also, if memory serves me right, the article refers to an older version of lua, and some of the functions have changed. For instance, the function lua_open() no longer takes any arguments. I think this is all covered in the discussion thread.

Share this post


Link to post
Share on other sites
If you're using the .NET Framework, you can use the Vsa which gives you capabilities to compile scripts at runtime. There's also the CodeDom which lets you use C# as a scripting language. I'm using Vsa in the project I'm working on.

Share this post


Link to post
Share on other sites
I would also go with Python or Lua. I found that a great book is Game Scripting Mastery . It walks you through integration of both in some examples as well as shows you how to build a scripting system from scratch. A very good read in general.

Good Luck

J

Share this post


Link to post
Share on other sites
Just a quick note about tools for parsing...


There are also tools out there other than Bison (YACC) and Flex (Lex). Personally I prefer ANTLR. Rather than having seperate apps the functionality of Bison and Flex are rolled up into a single tool. ANTLR is written in Java and generates lexers, parsers, and tree walkers in C++, Java, and C#. The big difference between ANTLR and Bison is that ANTLR has built in support to generate abstract syntax trees (AST's) based on the grammar file. In addition to the lex and grammar files it supports a third file for automatically walking the generated AST. While walking the AST you can trim and modify it as needed and you are not limited to the number of times you can walk the tree. You can also create multiple tree walkers if you want to break the processing down into a more finite scope.

Here's a quick list of features:

Written in Java.
Generates code for C++, C#, and Java.
Optionally generates abstract syntax trees (AST's).
Can use custom classes for AST nodes. This can be done globally or per token.
Existing grammars can be imported AND inherited.
Can use external lexers.
Creates lexers/parsers that work on both text and binary files (includes example for reading java .class files).
Supports lexer multiplexing (i.e. multiple lexers on a single input stream).
Fixed depth lookaheads and predicates
Libraries are included for Java, C++, and C#.
Has a large collection of existing grammars including C++, C, Java, C#, javascript, SQL, Corba, VRML, HTML, and Microsoft MDX (just to name a few).

If you're considering using Flex or Bison you should definitely evaluate ANTLR.

Share this post


Link to post
Share on other sites
Well After doing more searching, I did find the tutorial at gamedev on lua, and also the wiki on game programming and lua also. Those were really good articles / websites so I think I am gonna go the lua route.

-THACO

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this