🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Custom Scripts vs. Lua/Python/etc

Started by
2 comments, last by Arakon 19 years, 11 months ago
Hi Folks, I'm new to the scripting idea, but I figure it will make my life easier for what I need to do. I'm currently dabbling with an OpenGL tile/2d engine, and I hope to have some trigger based events that can be modified outside of compiled code (obviously where scripting comes in). Well, needless to say, all my time is spent designing ideas and doing graphics/numbers type stuff so I've never really bothered with scripting. My needs are not extreme. I just hope to have a few events and then responses to those events. I'd like you more experienced scripting folk to assess it and give me advice as to if I should just go ahead and do a custom script engine/language or attempt to use a current scripting library/language. Let me give you a primary example of what I need. My maps will have regions, and regions will have trigger events (entity enters or leaves a region). When the event occurs, the scripting language will have a generic function call on that event, and that function will essentially just provide the dynamic data to the compiled function. Here's some psuedo code of the scripting language (attached to or contained in the map file):

script:region001
{
   on_enter
   {
       move_entity_instantly(100,100);
   }

   on_exit
   {
       send_entity_message("Hello there.");
   }
}

In the compiled code, say, "ScriptFunctions.cpp" I might have a function to perform the action within the game code.

// The parser determined this function
// and sent the appropriate external variables

void ScriptFunctions::move_entity_instantly(Entity *ent, int x, int y)
{
    ent->move(x, y);
    // do some other junk
}

Remember this is all theory and psuedo code. So, do you guys think this sort of system would work, or am I terribly naive? All comments, suggestions, advice, and experience is appreciated! if you see a fatal limitation or flaw to this simple system, please tell. If you know an easier and better method, by all means. Thanks, -Catch
"Creativity requires you to murder your children." - Chris Crawford
Advertisement
Lua is pretty much perfect for what you want to do, I think. You could implement your own language, sure, but then you have to worry about implementing loops, comparisons, variable assignment, data structures, etc. There's a good example of binding C++ code to Lua on the lua-users.org wiki (plus lots of other good tutorials) - http://lua-users.org/wiki/SimplerCppBinding
Hm. I suppose the time it would take me to implement my own language is the same amount of time it would take to learn and use Lua.

Of course, it's possible I won't need to do a lot of things (loops, variable assignments.. don't feel like things I need).

As it stands though, with the way I set things up in my initial post, does that seem feesible? Does the design seem.. bad?

Do you think my idea would work? :)
"Creativity requires you to murder your children." - Chris Crawford
Also, if you go with Lua you could use a lib to help generate bindings. "tolua++" is handy for letting the lua environment use your C++ objects. Going the other way (calling Lua, or extracting info from Lua) is really simple and straight forward. After browsing the docs, I'd say you should be able to have a link between the two working in a few hours, to a few days (depending on how quick the concepts "click" for you).

This topic is closed to new replies.

Advertisement