It's very possible to do this. There are other options, but a method like this could be the simplest for you.
To create the array you would want, we'd make a two-dimensional CHAR (letter/character) array with the following code:
- Code: Select all
char rpg_text[5][256];
Essentially, this code a list of five groups (or lines of text) of 256 characters (which is the max for a single group of CHARs).
You would have to figure out some way to assign text to these lines, of course. Whether through normal script, text files, etc. I'll show you how you might do this in code:
- Code: Select all
char rpg_text[5][256];
strcpy(rpg_text[0], "My first line of text");
strcpy(rpg_text[1], "My second line of text");
// and so on ...
Each of the lines of text with the function "strcpy" assign a string of text to one of the ones in our rpg_text array. You may have noticed the first strcpy starts with "rpg_text[0]". If you didn't know already, arrays start at 0 instead of one, so an array with the size of 5 would be from 0 to 4.
To grab these lines of text and display them, we might use a special variable made in the gui, say something named "current_line" as an integer, and we would also have a text actor to display it. The code we would write would look something like this:
- Code: Select all
// Assigns the text of the text actor to the line
// number that current_line is at.
strcpy(my_text_actor.text, rpg_text[current_line]);
We would also have to keep track of some method to increase the current line we're at, so maybe in a mouse down event on a "next" button, or a "enter" key down event. But, we can't have the current_line variable go over the amount of lines in our text, so we'd have to check that each time the event happened.
- Code: Select all
// It's at 4, remember the size starts a 0
if (current_line < 4)
{
current_line = current_line + 1;
}
Then you have a basic RPG text system, extremely basic. You could also do choices, maybe. Say, check the number current_line is at and display options, and set the current_line variable based on which choice was made.
In the end, this exact example won't work on a large scale. You'd have to make variables for every line of text the actors say in the game, keep track of dozens upon dozens of variables, and it would just be an awful mess. For something simple though, this might work fine.
To show you something more complex than this, however, would make me write the whole engine myself!