Archived

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

frankd

making a script interpreter

Recommended Posts

frankd    164
I''ve been trying to implement a scripting system into my engine. Currently I''ve got it to tokenize a line of script, but now I''m stuck. So here''s a few questions: 1) I''m trying to make something fairly powerful, eg. it lets you use returning functions in the place of variables or constants. Do you think I''m trying to make it too powerful? 2) I''m planning to use the scripting system to implement scripted sequences and AI in the game. Is it going to be too slow? How about a sort of semi compiling script system ie. it replaces variable names in the code with a variable struct pointer before the code is run? 3) Obviously the code has to run with the engine "heartbeat" or whatever, not like: RunScript("hello"); which doesn''t return until the task is complete. So I''d have to have a basic multitasking system? How far is this suppost to go? thanks, Frank

Share this post


Link to post
Share on other sites
LilBudyWizer    491
Unless your goal is to learn how to write a scripting language I would suggest using Python. It has been a long time since I used a scripting system from a program and that was REXX so what follows may be a little dated. You basically load the scripting engine, define some system variables and functions relative to your application and call the script the user wrote. Your programs interaction with the user is through those variables and functions. Usually the system variables are just the basics that allows them to access other structures so you don''t have to spend a great deal of time maintaining them.

Speed is mainly a factor of design. If you provide functions that are powerful and complete enough that the user can pretty much get by with a few lines referancing only a few variables then speed isn''t much of a factor. If they have to do complex processing within the script then it will most likely be slow. Just as an example sorting a large file by reading and writing it in a script would be slow. A function you pass a filename to can be as fast as you are able to code. Generally you want to keep the scripts to under 100 lines a preferably 10 lines or so. That doesn''t mean limiting the user to that, but rather designing it so that they can accomplish the fast majority of what they need in that length of code.

Share this post


Link to post
Share on other sites
LilBudyWizer    491
Here are a couple of links for Python:

[A HREF="http://www.python.org/"]Python

[A HREF="http://www.python.org/doc/current/ext/ext.html"]Extending and embedding Python[/A]

Even if you decide against using it the site is a good referance on how to build your own including the source for Python.

Share this post


Link to post
Share on other sites