Talking and text

From Spheriki

Jump to: navigation, search

This tutorial demonstrates how to make and show a simple text box.


Open up one of your script files, the one where you have your game function will do nicely...

Type the following:

function Text(str) { 
  var font = GetSystemFont(); 
  var windowstyle = GetSystemWindowStyle(); 
  var x = 16; 
  var y = 16; 
  var width = GetScreenWidth() - 32;
  var height = font.getStringHeight(str, width); 
  font.drawTextBox(x, y, width, height, 0, str) 
  FlipScreen();
  Wait(); 
} 

function ClearKeyQueue() { 
  while (AreKeysLeft()) GetKey(); 
} 

function Wait() { 
  ClearKeyQueue();   
  GetKey(); 
}

Then save that, open your map, and insert a person entity onto the map (right click, Insert Entity > Person.)

In the dialog box that appears, fill in the name and filename for the person.

  • name: The_name_of_the_person
  • filename: the_filename_of_the_spriteset.rss

Then from the drop down list, select "On Talk" and type the following into the dialog box:

Text("Hello!"); 

Since the dialogue there is small, I also recommend adding an extra function, to keep as much scripting in the scripts as possible, e.g.

function OnTalkToJim() { 
  Text("Jim\n\tHello!"); 
  Text("How're you?"); 
}

And then you can just write OnTalkToJim() in the dialog, instead of having to struggle with the size. It also means that you don't lose anything if you delete the trigger, you just loose the link to it.

Note:

  • \n means a newline
  • \t means a tab


By Flikky (from the Sphere CHM, adapted and updated for the wiki.)