Legacy GM device_mouse_x_to_gui for all devices

Y

Yvalson

Guest
its extremely annoying to have to type out device_mouse_x_to_gui(0) 5 times

is there a way I can do this and have it onces for all the buttons
 

Paskaler

Member
Store the result in a global variable in Begin step event and then reference that variable everywhere else
 
Y

Yvalson

Guest
Use a for loop?

Code:
for (var i = 0; i < 5; i++;)
{
if device_mouse_x_to_gui(i)
    {
    // Do something
    }
}
I can't use a for loop because I don't use device_mouse_x_to_gui like that in my code I use it like this:

Code:
if(global.Pausing && !global.In_Store){
    if (point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 352, 192, 544, 384)){

    }
    
    else if (point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 704, 96, 896, 384)){

    }
my question is if I can replace the 0 with something like all to get it to work
 

chamaeleon

Member
I can't use a for loop because I don't use device_mouse_x_to_gui like that in my code I use it like this:

Code:
if(global.Pausing && !global.In_Store){
    if (point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 352, 192, 544, 384)){

    }
   
    else if (point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), 704, 96, 896, 384)){

    }
my question is if I can replace the 0 with something like all to get it to work
You can't. But why can't you wrap your code in the for loop with a break if necessary to stop iterating?
Code:
for (var i = 0; i < 5; i++)
{
    if(global.Pausing && !global.In_Store){
        if (point_in_rectangle(device_mouse_x_to_gui(i), device_mouse_y_to_gui(i), 352, 192, 544, 384)){
            ...
            break;
        }
   
        else if (point_in_rectangle(device_mouse_x_to_gui(i), device_mouse_y_to_gui(i), 704, 96, 896, 384)){
            ...
            break;
        }
}
Quite possibly some other logic changes may be necessary, but still seems like a viable approach.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I can't use a for loop because I don't use device_mouse_x_to_gui like that in my code
You can still use a loop...

Code:
if(global.Pausing && !global.In_Store)
{
for (var i = 0; i < 5; i++;)
    {
    var _mx = device_mouse_x_to_gui(i);
    var _my = device_mouse_y_to_gui(i);
    if point_in_rectangle(_mx, _my, 352, 192, 544, 384)
        {
        //
        break;
        }
    else if point_in_rectangle(_mx, _my, 704, 96, 896, 384))
        {
        //
        break;
        }
    }
}
 

ph101

Member
Off topic marginally but can someone explain why you would need to do that - seems to work fine for with purely (0) in windows using a usb mouse. What are the other 4?
 
Y

Yvalson

Guest
Off topic marginally but can someone explain why you would need to do that - seems to work fine for with purely (0) in windows using a usb mouse. What are the other 4?
because I'm making a mobile game in which the player might (may it be by accident) use his 3rd finger while the other 2 are still on the screen in that case only using [0] would unable to person to pause the game so I like to make my game detect as much fingers as possible in the case of the pause
 
Y

Yvalson

Guest
You can still use a loop...

Code:
if(global.Pausing && !global.In_Store)
{
for (var i = 0; i < 5; i++;)
    {
    var _mx = device_mouse_x_to_gui(i);
    var _my = device_mouse_y_to_gui(i);
    if point_in_rectangle(_mx, _my, 352, 192, 544, 384)
        {
        //
        break;
        }
    else if point_in_rectangle(_mx, _my, 704, 96, 896, 384))
        {
        //
        break;
        }
    }
}
alright well thanks it works really well still don't like the fact that you have to go through such a hurdle if there could just be a simple any but digress. thank you
 
Top