Archived

This topic is now archived and is closed to further replies.

Rickmeister

Scripting and C++

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Hey, I am writing a killer scripting language by hand called Xic-Script. I really think this will be of assistance to anyone not too knowledgeable about all the complicated shit that all those damn tuts teach. I said after a while Screw It I will do it my way. By Hand! Now I have a pretty interesting language on my hands that resembles C/C++ code alot. Check it out at http://www.x-i-c.com/ Let me know what you think. Post to the board and say its you. Thanks

Reality Makes Me XIC
I hack code: passion is my feul. Use my programs, experience genius.
http://www.x-i-c.com/

Share this post


Link to post
Share on other sites
This is not a flame.

Xic-Script is admitted in your page to be in the initial stages (you''re still dealing with function handling), but you post here that you''re writing a killer scripting language. It may eventually be a killer language, but until it is, let''s not jump the gun...

Let us know of its progress in the Announcements section.

I''m with Bunnz and Arakon who advocated using existing, well defined scritping languages. One major reason I''m for that is that your eventual customers/fanbase will be able to directly apply their scripting skills gained from mod''ing to real-world programming problems. Imagine if Unreal had used Python or Ruby; we''d have tons of qualified individuals now.

OTOH, there''s the desire to create something "specific" or "appropriate". Again I advocate Python or Ruby. They''re modern, object-oriented, extensible scripting languages and fully open source, meaning the code is yours to poke around in and modifiy for your purposes - come up with Rubikon or MyPyScript, tweaked to your heart''s content.

Returning to the original post/topic, I''m with Ronin_54: create a level editor. No self-respecting 2D map-based game is made without one, and even 3D games use them. Or whatever.

Share this post


Link to post
Share on other sites