Advertisement

scripting engine? plz help!

Started by May 21, 2001 08:23 PM
9 comments, last by Ghost within 23 years, 8 months ago
i am creating a simple iso rpg which i want to have a simple turn-based combat engine. Now i have NO knowledge of scripting engines but people have thrown that at me a lot, i was wondering: can someone please explain scripting engines (state machines + simple scripting) and how this might apply to me and if it is the only or easiest way to do what i want/need to do. thank you does tants'' book cover artwork at all? (creation)
There is tutorial about scripting languages by Jan Niestadt on www.flipcode.com so you can take a look.
I am also trying to create a scripting engine, but as you i am a beginner so I cant tell you much. I was thinking about using scripts to execute some events e.g. somebody steps on a trap and trap explodes, or to control behaviour of NPC''s. Of course it can be done without scripting, but if use scripts you (or game user) can easily change things e.g giving to a Big Black Dragon behaviour of a Goblin, or change exploding trap into teleport.
But writing such engine is not that easy (I learned it myself).

Hope it will help you somehow.

Krzys
Advertisement
scripting engines are not easy things to write, and difficult to talk about in general terms, since each game has its own unique needs in this department.

For game actors (i.e. anything with some sort of AI), there are some fundamental actions that the actor can do, like "turn", "move", "equip weapon", "use item", "attack", etc. These actions are part of the implementation of the actor and act as building blocks for more complex actions.

An example of a very simple script that makes a character walk around a square:

MOVE FORWARD 10
TURN LEFT 90
MOVE FORWARD 10
TURN LEFT 90
MOVE FORWARD 10
TURN LEFT 90
MOVE FORWARD 10
TURN LEFT 90

With this (very simple) script, you can make the character move forward 10 (whatever 10 means, be it pixels or tiles or whatever), turn left 90 degrees, and repeat three times, so that the actor winds up in the same location facing the same way when he is done.

This, of course, isn''t very interesting, and not very helpful as far as making a game, but it is a script.

These little actions can be made into larger action macros, like so:

ACTION WALKINSQUARE(SIZE)
MOVE FORWARD (SIZE)
TURN LEFT 90
MOVE FORWARD (SIZE)
TURN LEFT 90
MOVE FORWARD (SIZE)
TURN LEFT 90
MOVE FORWARD (SIZE)
TURN LEFT 90
END ACTION

You''ll notice that this is now more functionlike. A scripting language is often like this.

An actor in a game has a goal or a mission. He is engaged in DOING something. This is his state. An actor may have many states, like "wait", "patrol", "explore", "find enemy", and so on. the state of an actor determines what he will do, unless something unexpected happens.

You might, for example, want your character to march in a square during his patrol state. You might represent this like so:

STATE PATROL
WALKINSQUARE 10
END STATE

All this so far allows you to tell an actor what to do, but not how to respond to things. Unless your actor responds to outside stimuli, it is no better than a tree or a rock.

For this stuff, you need events. An event might be anything from an obstacle the actor has run into, his hitpoints being too low, sighting an enemy, or whatever.

EVENT HITOBSTACLE(OBSTACLE)
STOP ALL
AVOID (OBSTACLE)
CONTINUE ALL
END EVENT

The "STOP" might stop any actions that the actor is currently performing, and "CONTINUE" restarts them.

Also, there are conditions in which the choice of action for an event might differ. For example, when an actors hitpoints are low, the script for EVENT HPLOW will be fired. A number of things might affect what the actor does.

EVENT HPLOW
IF CANHEALSELF THEN
HEALSELF
END IF
IF NOT CANHEALSELF THEN
CHECKMORALE
END IF
END EVENT

The CHECKMORALE action will check morale, and send EVENT MORALEFAILURE if the check fails.

Beyond this, you probably also want a way to push and pop states, and so on and so forth.

So, to make an already long story short, making a scripting engine is not as easy as it sounds.

Get off my lawn!

Have any of you guys considered using something like TCL or Python for your scripts? I wouldn''t think it would be to hard to do, and it wouldn''t require too much additional coding effort. You could make a generic script template that would include your header and global information, and then use TCL or Python commands to call certain C funcitons as needed. Right?

quote:
Original post by voodoo_bluesman

Have any of you guys considered using something like TCL or Python for your scripts? I wouldn''t think it would be to hard to do, and it wouldn''t require too much additional coding effort. You could make a generic script template that would include your header and global information, and then use TCL or Python commands to call certain C funcitons as needed. Right?




It is a possibility, but you have to learn another programming language.
Krzys

quote:
Original post by voodoo_bluesman

Have any of you guys considered using something like TCL or Python for your scripts? I wouldn''t think it would be to hard to do, and it wouldn''t require too much additional coding effort. You could make a generic script template that would include your header and global information, and then use TCL or Python commands to call certain C funcitons as needed. Right?




It is a possibility, but you have to learn another programming language.
Krzys

Advertisement
Uuups, I posted my message twice. Sorry for that

Krzys
quote:
Original post by TANSTAAFL
scripting engines are not easy things to write, and difficult to talk about in general terms, since each game has its own unique needs in this department.



Actually, there are some specific cases where a Script Engine can be a very simple thing (they may not be easy to write, but you can easily reuse one). It was just a drop-in for the Scrolling Game Development Kit. Since the program was written in Visual Basic, all I had to do was write a little wrapper for Miscrosoft VBScript (this wrapper is available and open-source, if you''re interested -- see the site) and expose whatever aspect(s) of the program I wanted to expose. It was very easy to expose the whole internal object model of my program... almost automatic. Even if you''re not using VB though, as long as you''re dealing with dual-interface (or dispatch interface) COM objects, you could expose everything very easily.



"All you need to do to learn circular logic is learn circular logic"
"All you need to do to learn circular logic is learn circular logic"
Id rather go the ways of other companies and use DLL''s

--LordKaT
As Grudzio pointed out, I also recommend flipcode tutorial. Simple but down to the point.

go here and 2nd last topic right towards the bottom is Scripting Language Tutorial Series .

You might also want to take a look at
http://tos.maintree.com/babel/ and go to Editorial section. There should be some scripting stuff there. I don't know much about that site myself.

Also, there's a very obscure scripting tutorial for newbies here by rrc2soft. Go to Programming section, and you should see some 5 or so tutorials there. One of them is for scripting.
I say it's obscure, because it skips a LOT of essential parts and explanations. BUT, it's a very cut down, short tutorial, so it's a good place to get a "feel" for it, if you see what I mean. Then move onto read more hardcore stuff.
One last thing; he's spanish, and his tutorial is very hard to understand... He does write good tutorials though, overall. So long as you take your time reading it slowly, you'll find rrc2soft to be a rather good source for those who have no idea about tile game programming. If you are above Beginner though, his stuff is too simplistic.

By the way, if you make a bad post or multiple post by mistake, you can click on the Edit icon along the blue highlight bar where your name is. You can Edit or Delete your post from there.


Edited by - PugPenguin on May 23, 2001 1:43:00 PM

This topic is closed to new replies.

Advertisement