Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm kinda new to scripting and combining languages with each other so i have a question about something that confuses me about it.

If you want to script a game engine, do you embed the script in the engine or the engine in the script ?

In the first scenario, if you embedded the script in the engine, I can't really wrap my head around how that would work. Would you have this big script function you called every time you went through the game loop, passing along the inputs etc ? Like I said I have a hard time wrapping my head around it.

In the second scenario, if you embedded the engine in the script, I could see how it would be convenient to just treat the whole engine just like a object in the script, and call a simple function each time you wanted to create a new mesh or something. On the other hand how would the game loop inside the engine work ? Having a extra thread for that seems like it could complicate things.

I hope that made sense, otherwise let me know. You are welcome to explain further about how scripting a game engine works, if there are any general patterns you use, or link me to some good guide about it ( because i haven't really found any good one that deals with scripting game engines). But i would appreciate if you explained which of the 2 scenarios you use.

Ps. My engine I'm working on is written in c++ and I am planning to script in python 2.7 ds.

share|improve this question

3 Answers 3

Do you really need to script things?

If the project is just you, and you're not making a sprawling RPG you arent really going to gain much in the way of productivity by using a scripting language. But what about recycle time and ease of programming I hear people chime in with. Well.

  • C++ has a slew of excellent tools and debuggers (visual studio), scripting langauges often do not have such tools, making error tracking and debugging difficult, especially as script code often increases in complexity over time
  • You will have no performance issues with interop code
  • Your state will be contained in a single place, with no duplicity that often occurs with scripting code
  • If your recompile/re-boot time is longer than a few seconds, you should fix how your engine is compiling.

If you really absolutely must use a scripting language (and there are reasons it makes sense, for example, a sprawling RGP will have a lot of scenario logic that may be difficult to express in pure data) Its a good idea to push the scripting interfaces all the way out to the edges of your code. And only query single functions which contain no state.

You want to avoid building parts of your engine in script, and you certainly want to avoid duplicity of state at all points. You want to use script calls to answer "Questions", eg: "how do I react when I see the player", or "what sound do I play when I die". You dont want to be implementing your entire AI layer in script!.

share|improve this answer
    
I want to script because i want to learn how to script :) And also i think its nice to have another abstraction layer, makes creativity easier for when i am done with my engine :) Dont really know what to do with it yet. –  Fredrik Boston Westman Sep 25 '13 at 11:07

You embed the scripting engine inside the game engine.

I've never used this but you probably want boost::python

share|improve this answer

For my implementation, I embed the script in the engine (I'm using Lua and my engine is C++). I use Lua to define the contents of the game, e.g. monsters, items, map generation, and maybe using it to script the enemy AI (haven't reached that part yet).

What I do is I have functions in my engine that are used to register these definitions into the engine, which are called during the initialization stage. When I need to create a new instance of, say a monster, I simply refer to the definition of the monster, e.g. its stats, graphics and instantiate it with those values.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.