Gw Temp

Menu

Tutorial - 'Message Box Tutorial' by rapty

An item about RPGMaker 2000 posted on

Blurb

Learn how to make a basic message box script like in the Final Fantasy games, included is full source and files

Body

Personally, I've noticed a lack of tutorials that you can use to easily make your own message boxes. So, I decided to make my own.

To begin, I assume you have a map, character, and the script to load the character onto the map. If not, read tutorial.txt in the Sphere/doc directory. On your map, add an entity and choose a spriteset for it. Now, go to the code, and change to "On Activate (Talk)" Add the line msgbox("Hi");.


From left To Right: the add/edit entity box, the script.



After you've done this, create a new function in your script. Name is something like msgbox, or message. It should look something like this:



function msgbox(msg)

{



}




Now, to draw the message box. To do this, use LoadWindowStyle() and the .drawWindow property. The LoadWindowStyle, does exactly as it seems, loads a window style. A window style is the look of the message box that will appear. In my game, I'm using FFVII.rws. The .drawWindow property has some properties of it's own. x and y allow you to say where the box will show up, width and height show it's size.Your function should now look similar to this:



function msgbox()

{

LoadWindowStyle("FFVII.rws").drawWindow(40, 140, 200, 50);

}




Unfortunately, this still won't show the box. You gotta add one more thing, the FlipScreen() function. This is simple, and your function should now be...



function msgbox()

{

LoadWindowStyle("FFVII.rws").drawWindow(40, 140, 200, 50);

FlipScreen();

}




Try running your game now, you'll notice that a box flashes on screen for a moment. This means that the function works, but how are you supposed to read it if it just flashes? You'll have to insert a wait! This will require a new function, if you want to make your own, go ahead but for this tutorial, we'll use the one that comes in oldsphere.js. Add the following to your script:



function Delay(time)

{

var until = GetTime() + time;

while (GetTime() < until) {

}

}




And, add Delay(100); to the bottom of the msgbox function. It should now look something like:



function msgbox()

{

LoadWindowStyle("FFVII.rws").drawWindow(40, 140, 200, 50);

FlipScreen();

Delay(1000);

}




Save your script and run your game. You'll notice the box appears, and stays for a while. Now to add the text. For this tutorial, we'll be using the LoadFont().drawTextBox method. Loadfont() loads, well, fonts to be used in TextBoxs and the like, drawTextBox.. draws the textbox. I'll be using the FFX.rfn font for the purpose of this tutorial. Add the following to the msgbox function:



LoadFont("FFX.rfn").drawTextBox(40, 140, 200, 50, 10, "Hi");



So that the function looks like this...



function msgbox()

{

LoadFont("FFX.rfn").drawTextBox(40, 140, 200, 50, 10, msg);

LoadWindowStyle("FFVII.rws").drawWindow(40, 140, 200, 50);

FlipScreen();

Delay(1000);

}




You'll now notice that the box you created earlier now has the word 'hi' in it. You've finally created a working message box. Now to make it better!


Now that you have a working message box, let's make it stay up until the user presses a button, instead of having it timed. We can do this by creating a new function, then using this function. To start, change the Delay() from 1000, to 100. And move it to the top of the function. Now, create a new function called "Wait". It should contain the following code:


while(AreKeysLeft()) GetKey(); GetKey();


Now, where the Delay(1000); used to be, add Wait();. Congrats, you're now complete. The code should look similar to the code at the bottom!

The Message Box!

The Script as I use it in my game.
**Example code**



function msgbox(msg)

{

Delay(100);
var width = GetScreenWidth();

var font = LoadFont("FFIX.rfn");

var window = LoadWindowStyle("FFVII.rws");

window.drawWindow(40, 140, width / 2, 50);

font.drawTextBox(40, 140, 200, 50, 10, msg);

FlipScreen();

Wait();

}



function Delay(time)

{

var until = GetTime() + time;

while (GetTime() < until) {

}

}


function Wait()

{

while(AreKeysLeft()) GetKey(); GetKey();

}