Gw Temp

Menu

Article - 'The Programmatic Process' by Terin

An item about Game Design posted on Aug 9, 2003

Blurb

As a game developer, one usually doesn't know where to start on things. As a programmer, I give you the solution...

Body

Several people look at games like Chrono Trigger or Final Fantasy and ask themselves, "How in the world do I make a custom system into my game like that?" Believe it or not, the solution is actually quite doable.

Seeing as I work in RPGMaker, I'll be using that as my reference point. Keep in mind, this is general programming knowledge, so you can use it anywhere you go. Anything you can effectively script in, you can get something working using this process

You need to actually understand variables. Have you taken Algebra? You're proficient in variables already. Remeber how they had equations like Y = 3 + 2. Is that hard? No, Y = 5. For those of you not familiar with Algebra, it is the method of solving problems by using letters in place of unknown numbers. So in the instance that we want to know what X is and have: X = 1 + 1, X would equal 2. Using this knowledge, we could do something like Y = X + 2. In this case, Y would equal 4, as 2 (X) + 2 is 4. Pretty easy.

That's all you truly need to know. There are also switches in RPGMaker, which are actually what we call boolean values. Boolean values are basically 1 bit (8 bits to a byte -- so in one character/letter in this, there are 8 bits) that can hold either a 0 or a 1. A 0 indicates false (or off) and 1 indicates true. (or on)

Booleans are nice, because they don't take up the length that variables do and generally work more efficiently. Variables are used mainly to hold numbers, which you might eventually be able to convert to something else. (believe it or not, all characters/letters you see are represented by a number ranging from 1-256. Your computer is ALL numbers, it's converted so we don't have to convert it) Other languages, like Japanese and Chinese, have a ridiculous sum of letters. 256 doesn't cut it for them, that's why they have another character (letter) set that allows them to use numbers considerably larger. (1024 or something like that I believe) Remember how the Enter Name patch only shows two letters after you enter them? Because it uses the rest of the bits in the 1024 or whatever number to put in another letter... It actually holds 2 letters for us, 1 letter for Japanese/other.

Alright, that's the technical part. Basically, everything is a number. It goes down to bits and stuff, which can be really complex. We don't need to go that low. We really need to talk about how all of this actually applies to what you're doing.

So say you want to make a battle system like Zelda. Let's think for a moment on what we have to do. A good idea is to write this out on a sheet of paper and break up each little process... So in the top, we'd have a cloud or something representing the 'main idea' with 'Adventure Battle System.' Branching off of it, we'd write aspects: "Can block with shield" "Can swing sword" "Display health" and so forth.

These are all individual processes. Since we want only one character to do this, it'll be no problem to put it into global functions, known in RPGMaker as common events. Common events can be accessed everywhere. So just make some Parallel processes to constantly handle this.

Now, we need to document out how to do the "Swing Sword" idea from the battle system, so you'd break down the idea into the following, or what we'd assume. You have to THINK on HOW it would work:

Did I Attack? What allowed me to (fork condition with password before it)
Find Direction
Show Sword Swinging in that Direction
Check for Possible Hits to Other Creatures Around
Change Back to Normal Graphic

Now that you have this, you could reasonably write some code or scripts that did this. To find if they attacked, (or hit the Enter button) we would make a parallel process that contained an Enter Password prompt. Since we only want to check when it is hit, we'll have it wait for the Decision. (5) Now, since we want to only attack when we're in danger (or in some cases -- you shouldn't be able to whip out that sword and kill people in town unless you're a... erm, okay, nevermind... forgot my audience here -.^) so you'd make the parallel process only run when the switch "Can Attack" is on. Remember the boolean values? A switch is a boolean value.

So we know they can attack now. But it would run through eventually, so we need to prevent that from happening by putting a conditional in. We'll put a fork and test the variable for the password and if it equals 5. If not, then it won't execute any script inside. Forks are nice and our friends, and commonly referred to in programming languages as if...then statements. Basically, if something is true, then execute the statement... It's different for each language, but RPGMaker is pretty easy.

So now we need to find which direction they're facing. That's pretty easy too. Just make a fork again and check which direction the hero is facing (page 2 for forks, close to bottom) In each of these, we'll do a little animation of the character attacking. It could be a battle animation on top of the hero, a move event with a change graphic, who knows! You may want to include a sound too.

Before these conditionals, lets find out where the character is standing and store that in an X and Y variables. So it's a simple variable X = and Y = for their displacement. No problem right? This will help us in finding where the monster/attack victim will have to be.

**When scripting there will be a lot of trailing back and forth, writing one piece of code, then going back and writing some more elsewhere.**

Anyway, now that we have that, we'll fix it so a monster has to be on an X and Y within relation to the hero. So in the forks (hero facing left for instance) we'd modify X by subtracting one from it. That would be LEFT of the hero, correct? Indeed. Keep in mind that above the hero is actually Y - 1, and below is Y + 1. That confuses people a lot because they expect it to be like a graphic (the higher up, the higher the Y)

Now we know where the weapon will be with the X and Y, right? Well, we need to tell the monsters its time to get hurt. There'd be a section of code inside the monsters triggered by a switch "Weapon is Out" that would be turned on right before doing the animation of attacking. After the animation is through, "Weapon is Out" would be turned to off (monsters no longer get hurt) Now, you'll ask "How do I get the monsters to get hurt?" Well, just compare their X and Y coordinates to the X and Y specified off of the Hero. If they're the same, they just got hit. As far as some code for how to hurt them, that's up to you. Just another Y= equation from Algebra, pretty much.

So, we've done everything we wanted above, by writing it out and THINKING about it. See how easy that is? Okay, maybe not, but it's the best way to code it, so you don't have to type it over and over. (or copy/paste) Anything you ever code or script should be broken down into easy steps, much like storyline for an RPG should be. Just like notes from a class with roman numerals (or however you like it -- personally, I just indent mine) you can create a 'scheme' of processes in how to do things. When that's done, all you really have to do is code it. This way, you'll know the steps for what you were supposed to do everything.

From now on, try and doing things like this and you'll be less confused... I'll even include a sample for a battle system like Chrono Trigger:

I Battle System like Chrono Trigger
A. Move to Monster
i. locate event by X and Y
ii. continually move character until the hero reaches that X and Y (forks checking X/Y)
B. Show Menu
i. draw menu
ii. draw cursor
iii. keep track of cursor position
iv. move cursor within accordance to the position
v. check for if the enter key was hit to do something
C. Show Display
i. get hit points of heroes and store into variables
ii. draw with pictures (or use charasets with digits isolated -- I prefer this method)
D. Show Characters/Monsters Attacking
i. use the Move to command that we made in A.
ii. perform battle animation
iii. inflict damage, modify variables
iv. check for death, if so, kill character
v. move back to original location
E. Create Monster A.I.
i. just like battle events, get a random number or percent variable random feature
ii. fork conditions for each seperate ability

That's pretty much it, real quickly. You'd eventually want the characters to have skills, etc, too, but that's just another section that would deal with using the Menu.

Everything can be done by using this. It's a great way to plan on how everything works. In fact, the process of reverse engineering has been nicknamed 'Hacking,' which most people mistake for malicious people aimed at destroying your computer. Hackers actually break things down like this... Do so and you can join the elite ranks of... okay, I'm kidding about joining the ranks, but you will be a real, honest-to-god hacker if you start doing things in this manner.