• ### Popular Now

• 13
• 18
• 19
• 27
• 10

#### Archived

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

# How to do scripting for an RPG?

This topic is 5665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Me and a couple of friends are aiming to create a SMALL Zelda-style RPG. (C++, DirectX 7) The scripting we'll need will mostly concern dialogs with other people. For example, if you talked to the old lady in the house outside town, and then give the shopkeeper a certain stone, then he will say something... you get the point. I've STFW'd, but I couldn't really find what I was looking for. Most articles are about making your own scripting language, but I was thinking about using Lua. Is Lua good for this kind of task? Does anyone know any good tutorial, or have any good tips on how to manage things? EDIT: Spelling... /John [edited by - FunkyTune on September 14, 2002 7:18:24 AM]

##### Share on other sites
For a simple RPG, I''d do something like this:

Two boolean arrays, QuestItems and QuestFlags.

Each time a conversation occurs, you open up the file for that conversation (I''d preload these...but you get the picture.)

File would be in a format like this:

I+1,F+1
{
say:It''s nice that you got another item, but I already have one.
}
F+1
{
say:You already gave me the item.
}
I+1
{
set:I-1
set:F+1
say:Than you for the item.
}
I-1
{
say:I need this item.
}
*
{
say:I don''t know how I got here.
}

You read in a line, and check the conditions for that line. F+# means that QuestFlags(#) is Set, F-# means that QuestFlags(#) is not set, etc. Conditions would be comma delimited, and in reverse order of execution (initial conditions at end). * is a catch-all.

If all conditions on a row are set, execute the statements inside the { } block. set: would change the flags/items. say: would trigger dialog.

This is easily expandable, and not too difficult to write. If you wanted to add in comments support, prior to parsing the line, search the string for a unique character or character combo that you won''t be using (// or # for example), and blank the string after that.

Other options: instead of hard-coding the strings in this file, replace the strings with string identifiers, and put the strings in a different file. That would make localization easier. You could also encrypt that other file to reduce "cheating."

RomSteady - Test Locally, Test Globally, Test Early, Test Often

BYTE OldManWillYell = (1<<5) | (1<<6);if(Robbed the old mans shoes) Switches |= 1<<5;if(Kidnapped his daughter) Switches |= 1<<6;if(OldManWillYell == Switches)  Yell damnit, yell.