Scripting and C++

Started by
10 comments, last by Rickmeister 22 years, 10 months ago
Need some advice on how to start. I''ve got some knowledge of C++ (i''m not a guru-programmer, but I get along anyway..) The Story: I''ve written a couple of games, no fancy games, just plain old 2d tile games. In all of those games I''ve "hardcoded" the different maps, type of enemies and such stuff.. The sourcecode gets kinda messy after three levels, and I''m feed up with it after two.. It would be nice to have some sort of scripting language where I could specify the bitmaps, sounds etc to be loaded and some information about where all those powerups, traps, mines and that kinda stuff will show up on the map/level... I''m having a huuuuuuuuuge problem with this..I don''t know where to start.. I mean, to read from or save to a file is no problem, but to interpret that file into some sort of language that the, for example, tile engine understands is way above my knowledge..Atleast I think so. Anyway.. I don''t expect that anyone will post a complete Quake-style scriptengine as a reply, but atleast some hints that will help me to get started would be nice. I''ve read that VB tutorial on scripting but my VB skills are just about NULL so it didn''t help me at all.. I also tried to find some websites that would help me tackle the problem, but no luck..Maybe a future tutorial?? Thanks for any help on this topic Will code anything for free beer!
Advertisement
Never mind.. Found this GREAT article by Micheal Ireland that helped me to overcome my problems...

Will code anything for free beer!
You''re in about the same boat I''m in. Except I don''t know how to do file stuff, and I think I know all the rest.
I think I''ve figured out how I''m going to do my scripting engine, but don''t take my word as the best way to do it, as I''m not really sure what I''m doing...
What I am doing is, I have a map stucture in memory that contains all the data for the current map, and I also have atleast the current scripts loaded. I''ll store my scripts in an array of a structure that contains what function to run, and a couple of spots for data.
example:

class myScriptlet{   unsigned int funct;   unsigned int data1;   unsigned int data2;};myScriptlet somescript[100]; 


then to use the script, the engine would lookup what ever one it was on in a giant switch statement. Actually, I''m going to have an array of pointers to functions (you can do that right? I think I can... Been a while since I tried somthing like that) and then do something like this:

arrayoffuncs[somescript[x].funct](somescript[x].data1,somescript[x].data2); 


I''m sure my syntax is wrong, but maybe you can see what I''m doing. There is a LOT more to it than that in my scripting engine, but that''s the part that actually interprets. The part I''m not sure how I''m going to do, is load/save the scripts.

This is probably not the best way to do it, infact, with my luck it''s probably the worst, but it''s what I''m going with.


--Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People
We posted same time, hey, what article is that that helped you?

--Drakonite

[Insert Witty Signature Here]
Shoot Pixels Not People
If it can help goto flipcode there is a series with scripting engine.
At http://www.peroxide.dk/tut.htm to.

Why English rules?? C pas très malin tout ça!
_______________
Jester, studient programmerThe Jester Home in French
For scripting language needs, I''d highly recommend Lua.
It''s fast, free, and very easy to integrate. A tool called "tolua" is available that makes wrappers for existing C and C++ code. The first time I tried to put Lua into a test game-engine I was making, it took about 2 to 3 hours.

Milage will varry of course, depending on experience with compiling and linking problems and such. Oh, and since tolua uses a standard .h file to generate the lua stuff, it''s really easy to mark that up for a documentor, like doxygen.

Any questions, let me know, glad to give advice!
When it is about a ''simple'' thing like a way to store levels, I wouldn''t try to use scripts... When you create large levels, there is a huge chance you make a typing error, and then the whole level will not load...

I think it might be easier to create your own level editor, that saves the data to a file. The easiest way to set up your file is to write the size of the map first, and then you can just write away the ID''s of the bitmaps from left to right and up to down... This is easy to read and write from a program.

Just typing the level file might be quite hard to do, but creating a simple program to do the hard stuff for you should be possible, right?
Hi!

Take a look at:
http://www.flipcode.com/tutorials/tut_scr01.shtml

But it''s hard work, so I suggest you to use one of the following existing scripting languages:
Lua, Python, Simkin - they can easily be embedded in C++, nevertheless I''m working on a new scripting language myself, where you can use C++ classes without writting wrapper functions!!!
The idea is explained in the book: Game Programming Gems (A generic function interface) and I try to do it in an object oriented way!

Bunnz

Take a look at www.Bunnz.com
Have fun BunnzPunch'n'Crunch
For a description of the innovative UnrealScript language, go to http://unreal.epicgames.com/UnrealScript.htm. There is also a very interesting article from Robert Huebner at Gamasutra, its name is: "Adding Languages to a Game Engine" or so. Well, and then the Flipcode articles mentioned above. I''m going to place a scripting package on my homepage with these articles and some lex/yacc resources. programmier-page.de.cx

cö,Poizon"Close to the edge, round by the corner,down at the edge, just by the river"
Personally, I think that the problem with the Flipcode tutorial, and indeed many other such articles, is the total lack of detail on how to use Lex/Flex and Bison/Yacc. Reading the documentation for Flex and Bison is very awkward, and you have to have read pretty much all of both of them to even get the idea on how to use them together (and even then, it only gives a paragraph or two on how to do so). Basically, these tools are really powerful, but really awkward to use, and nobody who knows how to use them well is really interested in giving a tutorial. Maybe that''ll change soon.

This topic is closed to new replies.

Advertisement