Archived

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

Fuzztrek

Basic scripting engines

Recommended Posts

Hello Everyone I''ve been reading Mr. McCuskey''s book "Special Effects Game Programming with DirectX", and, while I find it *very* helpful and interesting, I was wondering what other methods of parsing files there are. Mason''s scripting engine is for particle engine files, and I plan on creating an engine with similar or more advanced capabilties than his. In SEGP, he cuts up the file into keywords which are put into a vector. The vector is then processed. I probably wouldn''t be thinking about this so much if it weren''t for the fact that particle system scripts do not just contain variable values. They also have some controlling info, like "at 0.5 color = rgba(255, 0, 255, 125)". I guess I''m not exactly sure how I should handly the file. Once I have the data I shouldn''t have much trouble getting it to do something, but I''m not sure how I should store it. Anyone have some ideas? I''m not sure if I''ve been to vague or not, and if so I shall explain in more detail. Any help is greatly appreciated. ¬_¬

Share this post


Link to post
Share on other sites
it's only hard if you make it hard on yourself

i made a simple BASIC-style scripting engine with... variables, all math, variable assignment, full conditional support (IF-ENDIF, IF-ELSE-ENDIF; nested conditionals too), and a few other things in... about 2 days and 500 lines of code. not hard at all.

one thing that makes things easier is to have the compiler sort out the expressions into RPN (postfix) notation. basically instead of

3 + 4

it ends up being

3 4 +

so for something like

(5+(x*(4+3)))

it'd end up being..

5 x 4 3 + * +

you can use stacks to make things easier. if it's a number, PUSH it to the stack. if it's an operator, POP the top 2 elements off, perform the operation, and PUSH the result onto the stack.

[edited by - Drakex on March 19, 2003 3:54:45 PM]

Share this post


Link to post
Share on other sites
"one thing that makes things easier is to have the compiler sort out the expressions into RPN (postfix) notation. basically instead of

3 + 4

it ends up being

3 4 +"


What happens if we need to turn a string into this ourselfs? It can''t just be Left-to-right Numbers then Left-to-Right Ops, since that''d ignore brackets.

For example, how would "(10+10)/20" be turned into this? Thankyou.


===========
Jack!!!!!!

Share this post


Link to post
Share on other sites
Hmm.. Interesting. What I find most confusing is how to parse it. Should I keep every thing in a vector of keywords? What is the fastest way to parse it? Right now it''s not slow or anything, but I''m just wondering. I should really look at some scripting books.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you want to know about parsing, get "the dragon book" which is the standard reference on compilers (tokenization and parsing are the two first steps of compiling).

If you want to actually finish a project, get some embeddable language like Python (very full-featured) or Lua (very easy to integrate, very light-weight). Then integrate into your engine.

Make sure you expose everything you need to the scripting system. When something needs configuration, you''d just call a script which calls back into your system to configure whatever it is (particle system, fire-breathing dragin, semi-naked pixie with sleep spell; whatever).

The nice thing is that it''s easy to rev the game (as opposed to the engine) this way, if you allow scripts to be re-loaded and re-run. You also get a console for very little extra work.

Share this post


Link to post
Share on other sites
quote:
Original post by Jack of Null Pointer
"one thing that makes things easier is to have the compiler sort out the expressions into RPN (postfix) notation. basically instead of

3 + 4

it ends up being

3 4 +"


What happens if we need to turn a string into this ourselfs? It can''t just be Left-to-right Numbers then Left-to-Right Ops, since that''d ignore brackets.

For example, how would "(10+10)/20" be turned into this? Thankyou.


===========
Jack!!!!!!


10 10 20 + /

.lick

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
10 10 + 20 /

There are a number of ways to convert infix->postfix notation. The most intuitive is to make a binary tree. Each non-leaf node in the tree is an operation and each leaf is a number. The children of a node get executed and pushed before the parent.

For instance, the tree to the above looks something like this:

20

/
10
+
10

Look at it sideways. The ''/'' is the root and is executed last. It has two operands (children), the 20 and the result of the addition. The ''+'' in turn has two 10s as its children.

Its easiest to think of it in terms of a tree. But there are a number of ways to convert without explicitly creating a tree.

As far as books go, the ''Game Scripting Mastery'' is definitely inferior to the dragon book. Note that the real title to the dragon book is ''Compilers: Principles, Techniques, and Tools'' by Aho, Sethi, and Ullman

If you just want a rich special effects data file, then it would likely be easier to just add a field for whatever extra customization you want. As has been mentioned, building a robust and flexible scripting engine is quite a task.

One final note, you could probably make a system that evades the annoying aspects of scripting while making your parsing algorithm easier to understand and debug. Look up ''bison'' or ''byacc''. If you''d like I can post some urls. The idea would be to use one of the parser-makers to set up the scanning code and then just tie that into data structures rather than worrying about things like looping/decisions/functions/arrays/other nastiness which goes along with a full-fledged language.

-D

Share this post


Link to post
Share on other sites