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

Radio and Check button script

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

A script to make a button like and within your game.


 Radio and Check button script
//////////////// Radio and Check button script ////////////////////
//
// Copyright Simon Donkers 27-1-2005
// www.simondonkers.com - gmmentor@simondonkers.com
//
// place in the draw event
// treat uninitialised varibles as 0
// for check button:
// selected = whether clicked on. needs to be initialised by you!!!
// for radiobutton:
// global.argument4 = id of the selected object
// argument0 = x
// argument1 = y
// argument2 = 0 = check button 1 = radiobutton
// argument3 = discription
// argument4 = class. clicking on an object of the same class will
// unclick all other. class = string. only required for radiobutton
//
/////////////////////////////////////////////////////
//button discription
draw_text(argument0 + 18,argument1 + 8-string_height(argument3)/2,argument3);
if argument2 = 0 then
{
        //check button
        brush_color := c_white;
        pen_color := c_gray;
        pen_size := 2;
        //draw button
        draw_rectangle(argument0,argument1,argument0 + 16,argument1 + 16);
        if selected then
        {
                pen_color := c_black;
                //draw cross in it
                draw_line(argument0 + 3,argument1 + 3,argument0 + 10,argument1 + 10);
                draw_line(argument0 + 3,argument1 + 10,argument0 + 10,argument1 + 3);
        }
        //if pressed
        if mouse_button = mb_left and pressed = false and mouse_x>argument0 and mouse_x<argument0 + 16 and mouse_y>argument1 and mouse_y<argument1 + 16 then
        {
                if selected then
                {
                        selected := false;
                }
                else
                {
                        selected := true;
                }
                mouse_clear(mb_left);
        }
        pressed := mouse_button = mb_left;
}
if argument2 = 1 then
{
        //radiobutton
        brush_color := c_white;
        pen_color := c_gray;
        pen_size := 2;
        //draw button
        draw_circle(argument0 + 8,argument1 + 8,8);
        execute_string('selected := global.' + argument4);
        if selected = id then
        {
                //draw circle in
                brush_color := c_black;
                pen_color := c_white;
                draw_circle(argument0 + 8,argument1 + 8,5);
        }
        //if pressed
        if mouse_button = mb_left and pressed = false and mouse_x>argument0 and mouse_x<argument0 + 16 and mouse_y>argument1 and mouse_y<argument1 + 16 then
        {
                if selected!= id then
                {
                        execute_string('global.' + argument4 + ' := id;');
                }
                mouse_clear(mb_left);
        }
        pressed := mouse_button = mb_left;
}

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

User comments

 Calle posted at 2005-10-15 22:04:37Quote
Very good. Your explanation wasn't too good though, could be improved...
 CY posted at 2007-07-29 10:28:21Quote
Error:
<redtextbox>
"COMPILATION ERROR in Script: script0 #Error in code at line 29: # ? # draw_rectangle(argument0,argument1,argument0+16,argument1+16) # ? # at position 74: Wrong number of arguments to function or script."
<redtextbox/>
 Simon Donkers posted at 2007-07-29 11:53:23Quote
You know, there is a reason why at the top of this page there is a big red block with bold text and a warning sign stating the version information.
 Ivo Georgiev posted at 2007-08-28 22:43:13Quote
To CY:
Is for GM5 you poor n00b :D

Reply

Name:
Site: