PDA

View Full Version : unique way of scripting a game



JernejL
08-10-2006, 11:08 PM
I had this great idea, what if in a game you'd use a actual pascal binary compiled script? for example free pascal compiler, you'd compile it to binary, it works on any platform as well, and you can redistribute the compiler with the game... ofcourse the script would have to be compiled on each platform individualy but this would generally allow a lot of freedom in scripting a game.

cairnswm
09-10-2006, 05:21 AM
One of the things I want to do is to create an EXE that gets distributed and then allow new scripts to be downloaded and used within the EXE making custom games as simple as writting a new script.

Most of the pascal scripting packages available are windows only.

The EXE then acts as an interpreter of the Pascal scripts it downloads. These scripts can obviously also be encrypted, compressed etc before being used in the Interpreter.

The AI in my games works this way. The DWS compiler is included into my game exe and loads text files into memory and interprets them as needed to make decisions. This enables a rule based AI system with full access to all the published internals of my game. (And publishing a new internal takes only a few lines of code)

WILL
09-10-2006, 09:00 AM
Well I've never tried anything this ambitious myself in a game yet. But I have made a somehwat limited interpriter for loading Game Map & AI Behaviour settings in a really long running game project of mine.

Everything was very tokinized and was rather simple, but it did allow for event 'trigger' nesting using a neat little trick that simply stored the actual tokinized script in the triggers them selves.

It was pretty sophisticated for me back then, my first complex design concept. (The game used pointers galore which caused a *ton* of memory leaks, *sigh* I was so new to OOP then. :P)

I've always wanted to take something like this to a farther level by making an AI that would have access to the compiler it's self. Thus being able to rewrite, recompile, run code completely autonomously...

Then again, this idea, though it intrigued me, sort of scared me a bit too... :eh: maybe I'm just watching too much Battlestar Galactica. :lol:

cairnswm
09-10-2006, 01:11 PM
I've always wanted to take something like this to a farther level by making an AI that would have access to the compiler it's self. Thus being able to rewrite, recompile, run code completely autonomously...

DWS actually stores the programs in compiled form in memory - but you can recompile at will. So you can actually have an AI script that creates other AIs based on rules.

jdarling
09-10-2006, 01:40 PM
Actually, just about any good scripting language already supports loading from binary form. Most even support cross platform loads (Indian issues taken care of by the VM).

Pascal Script, DWS both handle this the same way. Compile to "Native" binary format and run that. Lua, Java, JavaScript and some others handle this in a slightly different way. Where they compile to a VM code that is then machine independent. This allows you to compile once and run anywhere.

PHP and the likes are another story. They compile on the fly when the code is loaded. Like other scripting languages you can setup loaders so that you can encode/encrypt the source that is shipping with your games.

Now, some scripting languages offer a major speed improvement with the compiled versions (JavaScript, Java, DWS, etc...) while others only gain a minimal speed improvement (Lua, Pascal Script for Delphi, etc...).

In the case of Lua this is basically due to the fact that the back end is already highly optimized. Thus compiling only saves the time of interperting, witch with a proper interperter (one time compile with cache) is only seen the first time that the script executes.

Utilizing a standard compiler (FPC, Delphi, C++, GPP, etc...) and running those applications as scripts would be more of a library based aproach. Its been done as well. The cost/benifit of a scripting language actually out does the approach of using native compiled sources. One being different levels of compilation. In Lua the ability to de-compile is actually quite useful :). Of course you can also encrypt/encode the files so that they are more difficult to de-compile.

Anyways, my two cents and what I've found over the years at a 200,000 foot level.

Setharian
09-10-2006, 06:31 PM
in one project I'm currently working on our team has decided to use a system similiar to the OpenTools API Delphi IDE uses to extend itself....it allows nice OOP semantics and compiled down to native code....results are great speed, nice code and everybody loving it...the only cumbersome thing being reloading the dll at runtime safely....