• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

Strife

Scripting

15 posts in this topic

Does anyone know of a site or book that describes in fair detail how to go about creating and implementing a scripting language? It doesn''t have to be all that complex, I''d just like some basic knowledge (I''d like to be able to make an AI scripting language for a future game I''m planning). Also, I''ve looked at the recent article here, but it''s for VB programmers . It would be nice if any links had examples in C/C++, but if it at least explains everything well enough, that''s not a neccessity. If you code it, they will come... Commander M (a.k.a. Crazy Yank) http://commanderm.8m.com cmndrm@commanderm.8m.com
0

Share this post


Link to post
Share on other sites
Well, in theory, you''d want to create the "language", which is a bunch of commands like "walk", "jump", "spawn", etc., or whatever commands you''ll have. Each word is associated with a different action. When you write the script, you should parse the lines and convert it into integer tags as opposed to the string tags seen above (easier to work with integers than with strings). Once its in integer form, simply do some logic testing for what it wanted. For example, lets say "spawn" is 10 and "book" is 21. If this is the script:

spawn book


You read that string, and convert it into integers:

10 21


The logic (or lexical, i think, or is it symatic? I dont know the technical terms for the different stages! ) stage looks like this:

    
if(sentence[0] == 10) // We know we need to spawn something

{
switch(sentence[1])
{
case .....:
case.......:
case 21:
{
SpawnItem(ITEM_BOOK, x, y);
} break;
default: {.....}
}
}


You get the picture. If you have any questions, ill try to answer them.
0

Share this post


Link to post
Share on other sites
Also, to store the string/integer relationships, youd have a structure similar to this:

#define NUM_WORDS 2 // const int NUM_WORDS = 2, for you ''C++''ers

typedef struct language_tag
{
int id;
char word[20];
} language;

language LANGUAGE[NUM_WORDS] = {
{10, "spawn"},
{21, "book"},
};


BTW, that was me above. IE doesn''t like to save my login for my posts!
0

Share this post


Link to post
Share on other sites
for a basic scripting engine you might not need to buy a book.

how basic of a scripting are you thinking?
well, assembly style is about as basic as I can think...
you basically have one command per line and optional parameters after the command, which are separated by commas or spaces.

if you are able to code a program that can read
moveplayer 1 2
then you have a basic scripting engine. Once you think you have a good grasp on such a basic scripting engine, writing a more powerful one suddenly becomes within reach, as you will see.

if you would like psuedo code or have questions, feel free.
0

Share this post


Link to post
Share on other sites
Hi!

On www.flipcode.com you''ll find a nice tutorial on creating a scripting language. It covers everything from lexical analysis (looking at the characters in the script), parsing/syntax checking (is the script correct), code generation, virtual machines, etc... really good stuff. Even comes with source code. The author implements a basic STRING language as an example (concatenate and print strings)

He uses some lex (lexical analyzer) and yacc (parser generator) for the tutorial. Those might be a bit complicated for some people, but become important when designing more complex languages, so it''s something you should face (and not run away from).

Hope this helps,

MK42
0

Share this post


Link to post
Share on other sites
One thing I see missing from most, if not all, scripting
articles is the implementation. I see people recomending
such scripting languages such as JScript almost everyday.
If you use a pre-done language such as this, it looks
like its vm works with your engine through call-backs.
I have yet to try this, but am also wondering if anyone has?
The main question is, if you have some VM, how does it interact
back to your basic models or entities in your own engine(OOP)?
Or am I just heading down the wrong path?

Thanks!
0

Share this post


Link to post
Share on other sites
I am a firm believer in not recreating the wheel. If you want scripting in your game just grab a readily available scripting language and plop it in there. I don''t have time to be creating a custom language when I can use one someone else has already spent years of development on. The choice of scripting languages can be a bit tricky though. I go for small footprint, very fast, easy implementation, mature and track record in the game industry. I know of other people who have been very sucessful with other scripting languages but I prefer lua. I can drop it into an existing engine within a few hours and start scritping. Scripts can be precompiled to bytecode for that extra speed advantage in the final version. It is trivial to expose lua functions to C and C functions to lua. It has been used for many years. It has been used for many sucessful commercial games (Baldurs Gate, MDK2, Grim Fandango). It is also very extensable... By no means is lua the end-all-be-all of scripting languages but it works, its fast and its easy to use and implement. Thats good enough for me.

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

Share this post


Link to post
Share on other sites
I looked at the site real quick, once again it looks like you have to register your functions with Lua for it to call them.
So if I had some class like
class Hey
{
public:
void run();
.
.
void jump();
};

And I had some script like
run 5 times, then jump.

How would Lua work along side this class and script?

Thanks!
0

Share this post


Link to post
Share on other sites
This totaly depends on how you set up you implementation.

Lua's environment is persistant so while you are loading up your level you would register whatever functions you wanted to use while the game is running. Then when a certain objects AI update came around you would run its script using those functions. I would not create a unique function for each object as objects can be created and destroyed. I would create generic functions which would access the base behaviour common to that unit type. The script for each individual units could be kept with the unit so each could behave uniquely.

Thus,
Load level:
Register functions we are going to use to interface with our objects.
Also register functions used for evaluating objects environment.

Game Loop:
Update Object (Hey):
Hey sets itself as current ai object with ai interface and passes its script to lua.
Possible script
    
{
local enemy
local boss
if (enemy = EnemyNear() ) and IAmAwake() then
if (IAmHurt() OR EnemyStrength(enemy) > MyStrength() * 1.5) and
(IAmNotDrunk() OR IAmEnraged) then
RunAway()
IAmScared()
return
else
if EnemyWithinRange(enemy) then
Attack()
else
RunTowards(enemy)
end
return
end
end
if (boss = BossIsNear()) and IAmAwake() then
if BossIsMad(boss) then
Grovel()
return
end
Patrol()
return
else
if Drunk() > 0.50 and Intelect < 6 then
Sleep()
else
if Intelect < Rand(10) then
Drink()
return
end
Patrol()
end
return
end
if BossIsNear() and not IAmAwake() then
if Luck() > Rand(20) then
WakeUp()
Patrol()
end
return
end
}
function Patrol()

if (curpt = AtWayPoint()) then
if curpt == NumWayPoints then
MoveTo(WayPoints[1].x, WayPoints[1].y)
return
else
curpt = curpt + 1
MoveTo(WayPoints[curpt].x, WayPoints[curpt].y)
return
else
if HaveMoveToCommand() then
return
else
curpt = ClosestWayPoint()
MoveTo(WayPoints[curpt].x, WayPoints[curpt].y)
return
end
end
end

Philo

Edited by - Philomath on October 17, 2000 3:10:23 PM
0

Share this post


Link to post
Share on other sites
Thanks for the replies. Zip, I''ll test something like that out as that looks to be about what I wanted (something simple, but not too extremely low-level).

I might even check out that flipcode article more in-depth than I have (I saw some of it last night).

I''ll also probably check out Lua, as I''ve been meaning to look into it anyway (especially for use with ClanLib -- go CL!!! ).

If you code it, they will come...

Commander M
(a.k.a. Crazy Yank)
http://commanderm.8m.com
cmndrm@commanderm.8m.com
0

Share this post


Link to post
Share on other sites
Cool, thanks for the reply, but one more question.

So would you recommend a wrapper class that would
hold the Lua instance, and its functions would be mapped
into Lua. Sort of like the LuaWrapper acts like a V-table?


class LuaWrapper
{
Lua* pL (or however it is done )
ICurrentThing* pT (An object being ''ran'')

LuaWrapper()
{
// Set up Lua and map LuaWrapper''s functions,
// isDrunk and Jump, into it.
}

void RunScript( ICurrentThing* pO )
{
pT = PO;
// RUn the script found in pO into Lua
}

void isDrunk( ... )
{
... pT->IsDrunk();
}

void Jump( ... )
{
,,, pT->Jump()
}
}
0

Share this post


Link to post
Share on other sites
Taulin:

I think with the registered functions Philomath means stuff like EnemyNear() and EnemyStrength(enemy). Those are the hooks back into your engine.

Philomath:

I''ve looked at Lua before for scripting in a programming game (people write AI scripts and they can compete against each other). The project never got beyond the planning stage, but that''s another issue. Nevertheless, I found the Lua documentation to be a bit lacking in terms of ''example code''. I''ve also been looking at stuff like SeeR, Small, EiC and even Python (which was quite amazing in some ways). None of the scripting languages I mentioned above have been able to provide a rather seamless integration of Script-C/C++ and C/C++-Script. Take Lua for example, you still have to write wrappers which push/pop stuff from the stack. Although this in itself is fairly trivial, it''s still a pain in the ass.

OK, I might be a bit lazy here , but I''ve been researching cooler ways for almost seamless integration. For a native DLL, which were to be used by the script, you wouldn''t have to register a thing (just use the exports and unmangle the names). Of course, calling scripted-functions from C/C++ is another issue. But, how about letting the script-compiler generate a C/C++ file which does all the wrapping for you ... that would be a great help and save development time! I know, that some of these features are used in current scripting languages, but I''m still waiting for *the* scripting language ... if I have some spare time, I might have to do my own (I''ve done a C-Parser before).

Please don''t get me wrong about Lua ... it''s really fast and cool, but sometimes I''m just wondering why it''s so hard working with these things...

MK42
0

Share this post


Link to post
Share on other sites
Thats the way I''ve used it. I''m sure that there are other ways of setting it up. In fact as you can have multiple lua "environments" you could have a seperate lua environment for each object with only object specific data and functions available. I have never tried that but it would work as well (unless you hade too many objects or create them on the fly -vs- existing in a pool from level loadup). It really is up to personal preference and the task at hand. I use a seperate lua environment for user interface elements (buttons, pulldown boxes etc...)with its own unique set of C bound functions and data. I also setup and control my particle emmiters with lua scripts (usually precompiled, and no the script does not get called every frame). I figure the more I can accomplish with scripts the more generic and reuasable I can make the engines and tools.

Philo.
0

Share this post


Link to post
Share on other sites
Thanks for the replies. The scripting part
was never a problem. I just never read or saw any
examples of actual code ( pref. some class ) using
a scripting engine or VM. Have you all looked into
the JScript vm? I read on Gamasutra that I think
it was the Vampire:Masq used it.

Thanks!
0

Share this post


Link to post
Share on other sites
MK42:
EnemyNear() and EnemyStrength(enemy) are hooks to the engine, anything that takes extensive calculation (like pathfinding and line of sight stuff) is not suitable for any scriping language(Yea, I know EnemyStrength is just a lookup but hey its an example). I agree with you about the lua documentation, it does not have many examples. However the language itself is simple enough not to need to many (16 odd reserved words for lua3.2). Unfortuantly the implementation side of it could use many more examples and there explanation of tables is horrible (and they are so easy to use.. go figure).

I don't pretend lua is the best language by any strech of the imigination, every language has its pros and cons. Any of the languages you listed could be used effectively. I use lua because of its ease of implementation (one call to lua_open(), register your 'C' functions, and remember to call lua_close() when you are done, 20 min, depending on how many functions you need to register), its speed, I have yet to see a scripting language beat it in a comparison, and its extensability.

As far as registering you functions it can be a bit of work if you are adding it to an existing project. However Tolua is supposed to do this for you from header files (I've never used it though).

VBA with its com interfacing is close to what I think you are asking for, but I won't go there

Philo


Edited by - Philomath on October 17, 2000 5:24:35 PM
0

Share this post


Link to post
Share on other sites
Philomath:

I didn''t mean to bash lua ... it''s just that these ''limitations'' don''t make the scripting solution easier to work with. I guess tolua just looks at the PE Image of the LIB file and undecorates the mangled names ...

You are right, though, that lua is still one of the simplest scripting languages to use ... but, wouldn''t it be cool to have a scripting solution, which you could just drop into your project (no matter how complex it is) and it would work ...

VBA is *not* an option ... I refuse to use it

MK42
0

Share this post


Link to post
Share on other sites