Hey, pet, add this tutor 2 darkdreads little list thingy!!!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Hey, pet, add this tutor 2 darkdreads little list thingy!!!

Post by {Nathan} »

well, i took your advice, and (i started middle school today, and i got lost!!!) i got bored, and i serched google for "drakdread rpg scripting tutorial" and got it right away. i just though u might wanna have it under the darkdread thingy, just fyi, andyway, (i like commas) heres the tutor

Code: Select all

Well, it's been a while since I've written a new tutorial, so you'll have to excuse me if I'm a bit rusty. Well, I'm sure that, by now, you're all sick of reading about tile engines, so this tutorial will focus on some of the good stuff: Namely, how to write your own scripting engine!

This tutorial is aimed more at a novice to expert, so if you're a beginner, you may want to brush up on your skills before diving in. Let's get started...
	
"Write you own scripting engine!"

A Scripting Engine? What the...
Wouldn't it be cool if you could have your own scripted scenes (or cutscenes) ala Final Fantasy III? Well, if your tile engine is already coded, and you have your character pics and tiles drawn, you're just a few steps away from being able to use your tile engine for in game cinemas! Let's continue...

3. The Routines Explained
Well, first, you'll need to decide everything you would want your characters to do for a cutscene. The necessities would be moving around, and talking, so that's what I'll focus on.

    Setting Up

First, let's take a look at what some simple scripting code might look like, using our engine:

"talk"
This tells our routine what the character will be doing.
"Raven"
This tells our routine which character is acting.
"Hi, this is a scripted routine! All of our"
This is one line of text.
"actions are already written. We'll be "
Another line of text.
"preforming them now for you! "
A final line of text.
"talk"
"Rose"
"Okay, Raven, why don't you show them how "
"to move around a bit. "
" "
"talk"
"Raven"
"Sure... Here we go! "
" "
" "
"move"
"Raven"
"Up"
This tells our routine to move the character Raven up one space
"move"
"Raven"
"Up"
"move"
"Raven"
"Left"
"move"
"Raven"
"Left"
"move"
"Raven"
"Down"
"move"
"Raven"
"Down"
"move"
"Raven"
"Right"
"move"
"Raven"
"Right"
"talk"
"Raven"
"Okay, I'm tired now... I'm going to go to "
"bed! "
" "
"talk"
"Rose"
"Well... I guess that's it then. Bye! "
" "
" "
"done"
And we're done

Okay... If it doesn't quite make sense yet, don't worry. The code will be explained next!

    The Code!

For our scripting engine, we'll use a fairly small routine, which will read commands from a file, and do the appropriate actions. Here's how the routine would look:

SUB CutScene (FileName$)
The beginning of our sub. We'll need to load different files, so we have a FileName$ variable for that.
OPEN FileName$ FOR INPUT AS #2
Here, we open our data file to read the scripting commands.
DO
Begin a loop
INPUT #2, Action$
This will read a line from our script and determine what to do.
INPUT #2, Character$
This will find out which character will be acting.
IF Action$ = "talk" THEN
PRINT Character$
INPUT #2, Text$
PRINT Text$
INPUT #2, Text$
PRINT Text$
INPUT #2, Text$
PRINT Text$
If a character is talking, get their lines of dialogue and print them on the screen.
WHILE INKEY$ = "": WEND
Wait until a key is pressed.
ELSEIF Action$ = "move" THEN
This will move the character.
INPUT #2, Direction$
IF Direction$ = "Up" THEN
IF Character$ = "Raven" THEN
' Your code to move Raven up one space would go here.
ELSEIF Character$ = "Rose" THEN
' Your code to move Rose up one space would go here.
END IF
ELSEIF Direction$ = "Down" THEN
IF Character$ = "Raven" THEN
' Your code to move Raven down one space would go here.
ELSEIF Character$ = "Rose" THEN
' Your code to move Rose down one space would go here.
END IF
ELSEIF Direction$ = "Left" THEN
IF Character$ = "Raven" THEN
' Your code to move Raven left one space would go here.
ELSEIF Character$ = "Rose" THEN
' Your code to move Rose left one space would go here.
END IF
ELSEIF Direction$ = "Right" THEN
IF Character$ = "Raven" THEN
' Your code to move Raven right one space would go here.
ELSEIF Character$ = "Rose" THEN
' Your code to move Rose right one space would go here.
END IF
END IF
Now, you would call your routine to update the screen and show the characters' new positions.
END IF
LOOP UNTIL Action$ = "Done"
This will keep looping through your script until the Done command is encountered.
END SUB

Okay, that's the routine. Pretty simple, isn't it? Of course, you'll have to add your own appropriate code to be able to truly see it... But the code will work on it's own... It just won't be very exciting without any graphics!

Using The Routines
So, to finish up... You'll need to use a text editor such as notepad, to write your routines. Once you are satisified with one, save it (You could call it CINEMA1.SRC (S = scripting, R = routine, C = code)) in the same directory your program is in, and call it when you need it. To call the routine, here's what you do:

CALL CutScene("cinema1.src")

Or, you could do it this way too:

CutScene "cinema1.src"

What's the difference? Nothing, except there's less typing with the second method! Well... That's it... You're ready to begin scripting!

Final Notes
Well... With this tutorial, I've given you a simple way to do a scripting engine for your RPG. The best part about this is, no matter how much text and action your cutscenes will have, they will never use any of QB's precious memory, since the routine reads it's data from a file! If you've ever coded something big in QB, you'll remember the annoyance of 'Out of Memroy' errors. This routine is small, takes little memory, and let's you create as many minutes (hours, days, whatever!) of cinemas as you want!

Anyhoo... If you're having any problems with these routines... E-mail me (darkdread@hotmail.com) and I'll be glad to help out.

Hopefully, you've found this helpful. If so, e-mail zkman, and let him know that you want DarkDread to continue writing these tutorials! If there's a good response to this one, next time, I'll teach you guys how to write your own Legend of Lith 2 style engine... Or I might show you how to do a turn based battle engine... Stay tuned!

Oh, and if you're wondering about the names, Raven and Rose... Yes, those are the main characters of Distant Promises. ^_^

Cheers!

DarkDread 
man... that tuor kicks@#$!!! :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: :mrgreen: 8) 8) 8)
Image
User avatar
Pete
Site Admin
Posts: 887
Joined: Sun Dec 07, 2003 9:10 pm
Location: Candor, NY
Contact:

Post by Pete »

Thanks for sending that in!

I'll add it when I find the time...which may take a few weeks, or maybe a few hours. You never know.
m2j

Post by m2j »

I think that was in QBTM, its famialiar... It may even be the tutorial I learn scripting from.

matt
Post Reply