Scripting

Started by
12 comments, last by THACO 18 years, 9 months ago
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
Advertisement
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.
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
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.
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]
well it seems the mods have it, so ill go in that direction, thanks for all the advice

-THACO
Uh, if you just need to be able to use some functions, Angelscript's easy and very fast.
The best way to predict the future is to invent it.
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.
-------------"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."- Charles Babbage (1791-1871)
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.
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.

This topic is closed to new replies.

Advertisement