GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Script Submission » drag_and_drop (for quickie debugging) » 2022-12-16 00:56:33

felres
Replies: 0

Sometimes when testing stuff I need to move objects around that dont normally move. I always wished I could just drag them like a window so I made this script you can just drop at the step event.

Expand/// drag_and_drop([button?])
//
//  Enables the object to be drag and dropped with the mouse around the room.
//
//      button?         Optional. Can be enabled if the sprite works as a button.
//                      ie. contains 2 images of a button being pressed.
//
/// GMLscripts.com/license
{
    var xx, yy, isbutton, hold, pressed, released;
    // Implement global vars
    if !variable_global_exists("cursor_dnd")
    {
        global.cursor_hover = noone;
        global.cursor_dnd = noone;
        global.cursor_xoffset = 0;
        global.cursor_yoffset = 0;
    }
    
    // variables
    xx = mouse_x;
    yy = mouse_y;
    isbutton = false;
    if(argument_count>0) isbutton = argument[0];
    if isbutton image_speed = 0;
    
    // inputs
    hold = mouse_check_button(mb_left);
    pressed = mouse_check_button_pressed(mb_left);
    released = mouse_check_button_released(mb_left);
    
    // mark as hover instance
    if position_meeting(xx, yy, id) && !instance_exists(global.cursor_hover)
    {
        global.cursor_hover = id;
    }
    if(global.cursor_hover == id)
    {
        if(!position_meeting(xx, yy, id))
            global.cursor_hover = noone;
    }
    
    // detect click
    if position_meeting(xx, yy, id) && pressed && !instance_exists(global.cursor_dnd)
    {
        global.cursor_dnd = id;
        global.cursor_xoffset = x-xx;
        global.cursor_yoffset = yy-y;
    }
    // dragging
    if(global.cursor_dnd == id)
    {
        x = xx+global.cursor_xoffset;
        y = yy-global.cursor_yoffset;
        if isbutton image_index = 1;
        if released
        {
            global.cursor_dnd = noone;
            if isbutton image_index = 0;
        }
    }
}

#2 Re: Script Submission » Merge 2 lists, return 1. ds_list_merge(a,b) » 2022-12-16 00:47:36

xot wrote:

I'm somewhat surprised this doesn't already exist here. Perhaps someone else has submitted something like this in the past but it was never added.

Right? I`ve actually wondered why the scripts have not been updated in so long!

#3 Re: Script Submission » draw_collision_mask() » 2022-12-16 00:43:37

Does this work for rotated sprites?

#4 Script Submission » Merge 2 lists, return 1. ds_list_merge(a,b) » 2021-05-22 23:44:29

felres
Replies: 2

Hi, this is a self explanatory script. Takes 2 list data strucutures and returns 1. Thanks.

Expand/// ds_list_merge(a,b);
//
//      Returns a list with values from both lists. Will always destroy list a
//
//      a       list, to be destroyed
//      b       list, to be returned
//
//
/// GMLscripts.com/license
{
    var a,b;
    a = argument0;
    b = argument1;
    
    if !ds_exists(a,ds_type_list) && !ds_exists(b,ds_type_list)
        return b;
    else if ds_exists(a,ds_type_list) && !ds_exists(b,ds_type_list)
        return a;
    else if !ds_exists(a,ds_type_list) && ds_exists(b,ds_type_list)
        return b;
    else
    {
        for( var i = 0; i < ds_list_size( a ); i++ )
        {
            ds_list_add( b,  ds_list_find_value( a, i ));
        }
        ds_list_destroy(a);
        return b;
    }
}

Board footer

Powered by FluxBB