Thursday, November 7, 2013

A look inside RPG mechanics

It's very easy for any programmer to create an RPG game that includes all the mechanics of an RPG. It's quite another thing for a programmer to create NPCs that have the flexiblity and variety of a human DM.

So why is it so easy to perfectly translate one aspect of RPGs to computers while others remain practically impossible? I'm glad I imagined that you asked.

Well...

RPG mechanics are written in form common to almost programming languages, and it's common to programming languages because a program does what RPG mechanics do. All a programmer has to do is look at an RPG rulebook and directly translate the mechanics to the mechanics of a programming language
.

If you were to pick up a book on programming from the 70's or 80's you'd probably run into this simple diagram :

INPUT --> PROCESS --> OUTPUT

This legendary diagram shows what a program does in the most simple way possible; it takes some input, processes it, and gives back some output. Both input and output are static data. The only difference between them is whether they're coming in our going out.

Assignment

The most simple thing a program can do is assignment, which is taking input and putting it somewhere so that more interesting things can be done with it. If a programmer needed to store the number 40 for later reference, his program would look like this :

H = 40

He can then use A and get the number 40.

Pen and paper RPGs use assignment mostly in the character creation process and the storage medium is a character sheet.  There's no fundamental difference between typing hit_points = 40 into a program and writing Hit Points: 40 on a character sheet except that one of them is computerized.

Modification

Once a program has some input and has stored it in some place it can find it, it can then process that data and give back some output.

The most simple way a program can process data is to modify it. Let's say that a programmer needed to create a program that increased the value of a number by 2. The programmer would do this by using this
code :

H = H  - 2

The computer would first find what number A represents (the second one), then it would do the calculation A - 2, and finally, it would store that number in A.

This exactly what happens when your character has been hit for two points of damage. First, you look at your character sheet to find out what your current hit points are, subtract the damage and then erase 40 and write in 38.

If the sword your character was hit with was a +2 sword it could be programmed this way:

First, the damage modifier would be stored using it's own name :

D = 2
H = H - (2 + D)

First, the computer would find the value of D and H, then it would add D to 2 (resulting in 4 ), subtract 4 from 40, and finally assign 36 to H.

That's it for the first part.

No comments:

Post a Comment