Skip to main content
gamedev.net
🔒 Locked

Scripting for C++

Started by madsravn Jun 11, 2009 at 9:31 AM 1 replies 800+ views
Original Post
madsravn
madsravn
Hi, I have made a particle system and I want to implement some kinda scripting system so I don't have to re-compile everytime I want to change a little constant or some particle behaviour. I have heard you can get some scripting for C++ (An example would be how World of Warcraft is using LUA). So I was thinking if anyone know of some way to do this. I'd rather not code it myself, cause I'd like it to be some known language like Ruby, Python or LUA. If anyone knows anything, please link or tell me about it. Thanks in advance.
Scourage
Scourage
I prefer Lua as a scripting language. It can be a little tough to bind to C++, but there are helper libraries out there.

If you want to start simple, then you could also load a plain text file with one line per variable and use that to tweak your particle system.

Either way that you go, you're going to need to write some code. I think that with a simple text definition file for your particle system, you can get away with less code than binding Lua (or some other scripting language) to your particle engine.

Cheers,

Bob

[size="3"]Halfway down the trail to Hell...
flammable
flammable
I thing embedding a scripting lanquage is the easiest solution. I've tried Python myself (not without problems) and it took me about 2 days (about 4 hours not 48 [smile]) of reading the manual and trying (I use c++). To change a variable (possibly a particle behaviour) I use about 50-60 lines. I think using a scripting language is the least coding and the most bug save approche.

which scripting language to use is up to you, I suggest look at them all (and how to embedd them, which looks the easiest).

The approche of Scourage (load a plain text file) is a nice solution too. It saves you learning a scripting language (although changing some variables isn't that hard) and learning to embedd it but it gives you the new problem that you need to make your own "script"-loader.

say your a "script" looks like:
= 5
= 6
etc.

the loader would look like.
look for "<"
see what for token is after it (if invalid: error)
look for "> = " (if not there: error)
look for value and assign it to the corresponding variable.

Link you might use (some might be obvious [smile]):
Python
embedding python
lua
ruby

by the way if you use a scripting language I think it's easier to make one function to change particle behaviour with a enum (id, integer) as argument which property to change because making more function acsessable for the scripting language is much more work than make a id for every propery.

example:
instead of:
ChangeLife(float), ChangeSpeed(float)

ChangePropery(int propery, float value)
{
swith (propery)
case Life:
Life = value
case etc. etc.
}

but this is how I would do it and maby there are beter alternatives.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.