4
\$\begingroup\$

I have decided to use the Squirrel (probably doesn't matter much for this question) scripting language in my C++ project. I'm wondering how game developers usually handle scripting in their games. I've managed to run scripts, bind functions etc. - that is not the problem. I'm just not sure how a scripting system is actually implemented in a sensible way.

So far I have got a singleton ScriptManager, which owns a virtual machine and can interact with it.

Some specific questions:

  • Does every functionality, that you want to control with scripts, need to be bound manually or can you somehow make all functions/classes available to your scripts? (I do not intend to use scripting everywhere in the final game, but it would make the development process a whole lot easier.)
  • How should squirrel scripts be structured? Should they represent some kind of library, that you load, or just a set of commands that get executed whenever a game object wants to? If the former approach is better, how would such a library look like and how would the execution of the script be triggered?

I would be great if you could point me into the right direction! Thanks!

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

There's a few routes that you can take. Some include making an event type system where actions in your C++ code map to functions directly/indirectly in your scripting system. So, if you read that a player presses the up key in game, that will send an event to the scripting system that will then decide what to do.

You could also hard code certain actions and map the scripts directly to them.

Also, for data retrieval one might create a global class/singleton/etc to retrieve data from the game for usage in scripts (or pass through to functions)

Also, in terms of structuring, you could group them by action/category, so all of the player's scripts could go in one file/folder and then broken up by action and so on.

There's many games that have employed scripting (Garry's Mod:Lua, Battlefield series uses Python I think, TES uses their own system, etc.) Try looking through those and look at modding guides

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, that's already really helpful and I'll have a look at some modding guides of the various games! However, I'm still unsure about the first question. I guess there is no way to make the whole c++ project available for use by the scripts apart from binding all the classes/functions manually, am I right? \$\endgroup\$
    – Alex
    Feb 17, 2014 at 16:54
  • \$\begingroup\$ Not really unless you have some sort of managed layer. \$\endgroup\$
    – CobaltHex
    Feb 17, 2014 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .