Simon Donkers's Game Maker site siteSimon Donkers's Game Maker site
This resource is created for Game Maker 5 and isn't compatible with the latest version of Game Maker.
My apologies for the inconvinience.
Version: GM 5 Views: 13813 Script, Game Maker 5 compatible
Filesize: 3473 byte Creative Commons License

Message box script

1/52/53/54/55/5 (26 votes)

A script for a text screen in for instance an RPG. Very easy to use. Will display an image of the person wo is talking. The script is also capable of handling large amounts of text.


 Message box script
//////////////// Message box script ////////////////////
//
// Copyright Simon Donkers 27-1-2005
// www.simondonkers.com - gmmentor@simondonkers.com
//
// argument0 is the text to draw
// argument1 is the sprite of the speaker
// argument2 is the color of the text
//
/////////////////////////////////////////////////////
string:= argument0;
brush_color:= c_gray; //background color of the menu box
font_color:= argument2; //text color
font_size:= 18; //text size
if sprite_get_height(argument1)<string_height_ext(argument0, -1, view_width[0]-sprite_get_width(argument1)-50) and string_height_ext(argument0,-1, view_width[0]-sprite_get_width(argument1)-50) < view_height[0]-40 then
{
        height:= string_height_ext(argument0,-1, view_width[0]-sprite_get_width(argument1)-50);
}
if sprite_get_height(argument1) >string_height_ext(argument0, -1,view_width[0] - sprite_get_width(argument1) - 50) then
{
        height:= sprite_get_height(argument1);
}
if string_height_ext(argument0,-1, view_width[0] - sprite_get_width(argument1) - 50) >view_height[0] -40 then
{
        height:= view_height[0]-40;
}
while argument0!= ''
{
        string:= argument0;
        //if message is smaller then the screen
        if string_height_ext(argument0, -1, view_width[0] - sprite_get_width(argument1) - 50) < view_height[0]-40 then
        {
                string:= argument0;
                argument0:= '';
        }
        else
        {
                i:= string_length(argument0);
                while string_height_ext(string, -1, view_width[0] - sprite_get_width(argument1) - 50) > view_height[0]-40
                {
                        string:= string_copy(string,0,i-1);
                        i-= 1;
                }
                while string_char_at(string,string_length(string))!= ' '
                {
                        string:= string_copy(string, 0, string_length(string) - 1);
                }
                argument0:= string_copy(argument0, string_length(string) + 1, string_length(argument0) - string_length(string));
        }
        draw_rectangle(10, view_height[0] -30 -height, view_width[0]-10, view_height[0]- 10);
        draw_sprite(argument1,-1, 20,view_height[0] -20-height);
        font_align:= fa_left;
        draw_text_ext(sprite_get_width(argument1) + 30,view_height[0]- 20-height,string, -1,view_width[0]-sprite_get_width(argument1)-50);
        screen_refresh();
        io_clear();
        keyboard_wait();
}

Tip: Have a look at the tutorial How to execute a script

User comments

 JakeX posted at 2005-06-18 02:44:57Quote
This is a very nice script. I use a GM-6 compatible version of this in my games.
 buzzer posted at 2005-07-19 21:03:07Quote
can you send me that version 6 compatible script?
my email is electro_buzzer@hotmail.com.
 scronix posted at 2005-08-07 20:32:01Quote
When I run the game with the script I got an error. :( How does it works? Can anyone help me? Sounds like a cool script.
 zigzag posted at 2005-10-23 17:06:35Quote
It says argument 0 is an unknown varible.
This seems wrong...
 Simon Donkers posted at 2005-10-23 20:54:04Quote
That's because you need to provide argument0. Have a look at:
http://gamemaker.simondonkers.com/index.php?mode=view&fileid=2
for more information.
 Delta Entertainment Chairman posted at 2006-01-23 18:47:42Quote
This seems like a very nice script and all, But it does not appear to be Game Maker 6 Compatible. What must be done to make this so? My email is kingnimbus05@yahoo.com
 MyuuMaster (myuusmeow) posted at 2006-03-26 00:45:39Quote
A few key variables were removed in GM6.
Just remove some formatting (Like font_align) and it'll work.
 Megaspit posted at 2006-03-31 04:48:31Quote
Apparently, the draw_rectangle function is screwed up. That's the only error I got in GM6.
 norlick posted at 2006-04-18 10:04:59Quote
i think everything in gm6 works fine except draw_rectangle, which needs an outline(either true or false, true being draw outline ONLY, false being fill interior ONLY), otherwise works fine
 rockout posted at 2006-08-28 18:01:05Quote
unknown variable veiw_width

scripts a bit buggy... help? cant get it to work

SD: Did you perhaps notice the big red block with the yellow warning sign and bold text on the top of the page? The thing that tells:
"This resource is created for Game Maker 5 and isn't compatible with the latest version of Game Maker.
My apologies for the inconvinience."

That means this resource is made for Game Maker 5 and doesn't work in the latest version of Game Maker aka Game Maker 6.
 Music Matter posted at 2006-09-29 06:31:13Quote
/string:= argument0;
That's The First error i got

while argument0!= ''
is the second. this is very weird!
& I AM USING GAME MAKER 5!!!
 music matter posted at 2006-09-29 06:34:52Quote
simon, i need your help! my problem is up there!
 arylic singh posted at 2007-04-02 04:41:49Quote
please can any one help me please tell me can this work in v6 course wanted to make a pokemon game
 Doolza92 posted at 2009-01-23 10:08:23Quote
To convert this script over to GM6, just replace view_width & view_height with view_wview[0] & view_hview[0]

As simple as that :)

Excellent example too, I am currently using it in one of my games... Yes! of course I'm providing credit!
 Chris Renna posted at 2009-10-22 08:04:56Quote
Hey you know how you said it doesn't work with the latest version??? well it does now :) enjoy guys and I take no cred for this, it was easy really

//////////////// Message box script ////////////////////
//
// Copyright Simon Donkers 27-1-2005
// www.simondonkers.com - gmmentor@simondonkers.com
//
// argument0 is the text to draw
// argument1 is the sprite of the speaker
// argument2 is the color of the text
//
/////////////////////////////////////////////////////
string:= argument0;
brush_color:= c_gray; //background color of the menu box
font_color:= argument2; //text color
font_size:= 18; //text size
if sprite_get_height(argument1)<string_height_ext(argument0, -1, view_wview[0]-sprite_get_width(argument1)-50) and string_height_ext(argument0,-1, view_wview[0]-sprite_get_width(argument1)-50) < view_hview[0]-40 then
{
height:= string_height_ext(argument0,-1, view_wview[0]-sprite_get_width(argument1)-50);
}
if sprite_get_height(argument1) >string_height_ext(argument0, -1,view_wview[0] - sprite_get_width(argument1) - 50) then
{
height:= sprite_get_height(argument1);
}
if string_height_ext(argument0,-1, view_wview[0] - sprite_get_width(argument1) - 50) >view_hview[0] -40 then
{
height:= view_hview[0]-40;
}
while argument0!= ''
{
string:= argument0;
//if message is smaller then the screen
if string_height_ext(argument0, -1, view_wview[0] - sprite_get_width(argument1) - 50) < view_hview[0]-40 then
{
string:= argument0;
argument0:= '';
}
else
{
i:= string_length(argument0);
while string_height_ext(string, -1, view_wview[0] - sprite_get_width(argument1) - 50) > view_hview[0]-40
{
string:= string_copy(string,0,i-1);
i-= 1;
}
while string_char_at(string,string_length(string))!= ' '
{
string:= string_copy(string, 0, string_length(string) - 1);
}
argument0:= string_copy(argument0, string_length(string) + 1, string_length(argument0) - string_length(string));
}
draw_rectangle(10, view_hview[0] -30 -height, view_wview[0]-10, view_hview[0]- 10,1);
draw_sprite(argument1,-1, 20,view_hview[0] -20-height);
font_align:= fa_left;
draw_text_ext(sprite_get_width(argument1) + 30,view_hview[0]- 20-height,string, -1,view_wview[0]-sprite_get_width(argument1)-50);
screen_refresh();
io_clear();
keyboard_wait();
}
 Zach posted at 2009-12-21 09:46:55Quote
COMPILATION ERROR in Script: scr_dialoguebox
Error in code at line 40:
draw_rectangle(10, view_height[0] -30 -height, view_width[0]-10, view_height[0]- 10);

at position 93: Wrong number of arguments to function or script



This is what happened when I tried to see the result, and I'm not sure if it is the fact that I don't have your sprites or because the code is wrong, somebody help please.
 Zach posted at 2009-12-21 09:55:12Quote
Where do I get the sprites for the code, since I fixed the problem about executing the it?
 Lestat posted at 2010-08-13 13:06:32Quote
Once again its very good. Although explaining how to define the text colour in the argument would be nice.

Reply

Name:
Site: