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: 2694 Script, Game Maker 5 compatible
Filesize: 2383 byte Creative Commons License

Textfield script

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

A script which generates a basic windows text box.


 Textfield script
//////////////// Textfield script ////////////////////
//
// Copyright Simon Donkers 27-1-2005
// www.simondonkers.com - gmmentor@simondonkers.com
//
// This script generates a windows text box on the x and y with preset length.
// All characters typed after the length is reached will be ignored
// max. 80 characters can be typed in this text box!!!
// set 'treat uninitialised variables as value 0' to true
// the local variable text contains the typed text
// place in the draw event
// argument0 = x
// argument1 = y
// argument2 = width
//
/////////////////////////////////////////////////////
//draw box
brush_color := c_white;
pen_color := c_black;
draw_rectangle(argument0,argument1,argument0 + argument2,argument1 + string_height('ABC') + 5);
//if string doesn't fit in box shorten it
if selected then
{
        while string_width(keyboard_string)>argument2-5
        {
                keyboard_string := string_copy(keyboard_string,0,string_length(keyboard_string)-1)
        }
}
//if text isn't string make it one
if string(text) = '0' then
{
        text := '';
}
//draw text
if selected then
{
        draw_text(argument0 + 3,argument1 + 3,keyboard_string);
}
else
{
        draw_text(argument0 + 3,argument1 + 3,text);
}
//if pressed than select it
if mouse_x>argument0 and mouse_x<argument0 + argument2 and mouse_y>argument1 and mouse_y<argument1 + string_height('ABC') + 5 then
{
        set_cursor(cr_beam);
        if mouse_button = mb_left and selected = false then
        {
                keyboard_string := text;
                selected := true;
        }
}
else
{
        set_cursor(cr_arrrow);
}
//if pressed somewhere else than deselect it
if selected = true and mouse_button = mb_left and (not mouse_x>argument0 and mouse_x<argument0 + argument2 and mouse_y>argument1 and mouse_y<argument1 + string_height('ABC') + 5) then
{
        text := keyboard_string;
        selected := false;
}

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

User comments

 joe posted at 2005-02-19 05:26:15Quote
It aint working buddy?it says unknown variable selected?
 Yibbon posted at 2005-02-19 07:04:35Quote
// set 'treat uninitialised variables as value 0' to true

-Look more closely....
 Ickie posted at 2005-05-14 05:37:41Quote
Nice script, now only gotta figure out how to put two in one room. o_O
 Javano posted at 2008-02-03 03:15:41Quote
i dont see 'treat uninitialised variables as value 0' anywhere in there

Reply

Name:
Site: