tying in a scripting language

Started by
4 comments, last by dusty_one 16 years, 9 months ago
So I was beta testing an mmo that came out and got some scripting errors, which got me to thinking, how exactly do you integrate another language to handle parts of your game? Lets use python for example if you can, since I know that language a bit :) .
Advertisement
dusty_one,

Good question. The answer is completely irrelevant of the language you're embedding however, whether it be Lua, Python, Pike, &#106avascript, etc...

In general, the scripting language is the embedded language within a host environment or host language, such as C++. Then, using the host environment you introduce new data types, external methods, etc...and bind them to their equivalent within the scripting language.

For example...

Lets say I want to kill a player from a script method called "KillPlayer(Player)."

I introduce this method and the 'Player' data type into the scripting language via whatever mechanism the language exposes to the host environment. This is different depending upon the embedded language, and what language it's interpreter is written in.

Usually, data types are mapped to structures or classes within the host environment, so a "Player" type within the scripting language might be associated with a Lua_Player C++ class. Similarly methods or functions within the scripting language are registered as callbacks within the host environment.

So when I say "KillPlayer(Player thisPlayer);" in the scripting language, it actually has created a C++ (depends on the host language of course) object which it associates with the object thisPLayer and when I pass it to the KillPlayer method, it actually passes it to a C++ method called something like Lua_KillPlayer().

So the short answer is, the constructs and methods used within the scripting language are parsed and interpreted by the embedded language, and then acted upon by the host environment or language via callbacks and associated data types.

Although I didnt do a very good job of explaining it, you can find the Python documentation for Extending and Embedding Python Here.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
if you know python a bit, then you probably know http://www.python.org/doc/
So that's how it's done. Is there any noticeable downfall in terms of performance? I would imagine that if some script feature is executed very often it would have some sort of lag, though I could be wrong.

M.
<work in progress>
Quote:Original post by M Eversberg II
So that's how it's done. Is there any noticeable downfall in terms of performance? I would imagine that if some script feature is executed very often it would have some sort of lag, though I could be wrong.

M.


"Depends" ™

Using a language that's reinterpreted every runthrough as the innermost loop of a pixel blitter is on the obvious no-no side of things. But if you're going down that far, you're no longer really scripting using the language, so much as you are writing every damn thing in it.

On the other side of the spectra, there's JITed bytecode languages which can be used as "scripting" languages, which do just fine on either side of the arbitrary divide -- as the host or as the embedded language.
thank you for that explaination jw. I had been curious as to how data was passed inbetween the env and the scripting language. I had read an interview of one of the Vanguard devs and he was talking about one of the biggest set backs for the dev team on that game was that they were doing the world and its interaction without a scripting language.

This topic is closed to new replies.

Advertisement