Archived

This topic is now archived and is closed to further replies.

wrathgame

How do i implement a script engine ! aghh

Recommended Posts

wrathgame    122
Hi all, I currently use a self made database to store stuff like items .. ie image id and stats etc. What I would really like is a script engine so i can do something like OnEquip if player.class = mage then return true else player.hp = player.hp - 10 message "you feel a slight pain and drop the weapon" endif end can anyone point me in a direction ?? im guessing i will need to make a compiler which converts the script to a form of binary byte code (to save on space and speed of interpreting) and then the interpretor Thanks for any advice on this :-) -Tim

Share this post


Link to post
Share on other sites
Tim,

Basically what you are trying to do is create your own restricted natural language. There are heaps of books on this topic and stacks of web sites (google search on ''restricted natural language'' works wonders).

There are many different ways to do it, you can write your own compiler that translates the script into something else. You can use someone elses script and compiler that they have already written or you can set up the scripts as resources that you define macros for so you turn the bare script into proper executable code... of course, unless it''s in an external library, you will have to recompile your entire app if you change a script.... that is a quick way to have scripting though.



-- And that''s my $0.02 worth --

Hang on, where I come from, $0.02 is rounded down. Does that mean my opinion is worthless or priceless?

CHROM

Share this post


Link to post
Share on other sites
gmcbay    130
Consider using an existing scripting language.

Unless you have some very special purpose needs or you want to create a scripting language for the experience more than for its utility, you are better off making use of work already done by scripting language experts from around the world.

Some popular scripting languages that are easy to embed in your own apps and have good runtime speed include:


Lua

http://www.tecgraf.puc-rio.br/lua/


TCL

http://www.scriptics.com/


Small

http://www.compuphase.com/small.htm


There are many others, both big (like Python or even Java) and small. Do a web search for other alternatives!

Share this post


Link to post
Share on other sites
wrathgame    122
Thanks all...

I have had an idea...

I was working on a compiler for my language and was thinking back when i made a assembler for my a level project .. and i suddenly though..

Why make a script which makes byte code which is interpreted by a VM.. why not make machine code ?

Im not sure how you could dynamically load code into an executable piece of memory though ? anyone know if you can ? the benefit from this of cource would be V fast code ;-)

Thanks

Tim

Share this post


Link to post
Share on other sites
gmcbay    130
You just walked in a circle and reinvented the DLL (or .so, if you''re a UNIX programmer).

Loading DLLs into memory and executing them is very easy.

Share this post


Link to post
Share on other sites