Sign in to follow this  

tying in a scripting language

This topic is 3860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :) .

Share this post


Link to post
Share on other sites
dusty_one,

Good question. The answer is completely irrelevant of the language you're embedding however, whether it be Lua, Python, Pike, javascript, 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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this