• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Sending mouse click location over networked game, versus x/y coord

C

Carcophan

Guest
Hello Everyone.


I was able to get the player to update their location on the map, but not the 'mouse click' they do on screen.

I figured I could just duplicate the movement portion of the object/scripts, but it doesn't seem to be working right.



Code:
 case KEY_RELEASE: //movement
        name = buffer_read(buffer,buffer_string);
        key = buffer_read(buffer,buffer_u32);
        xx = buffer_read(buffer,buffer_u32);
        yy = buffer_read(buffer,buffer_u32);
        if instance_exists(obj_slave)
        {
            with(obj_slave)
            {
                if playerName = other.name
                {
                    x = other.xx;
                    y = other.yy;
                    key[other.key] = false;
                }
            }
        }
        break;

case KEY_PRESSED:
//same as Release code basically
break;
Tried updating the above code, with this below:
Code:
 case CLICK_LEFT: //action click
        name = buffer_read(buffer,buffer_string);
        key = buffer_read(buffer,buffer_u32);
        xxx = buffer_read(buffer,buffer_u32);
        yyy = buffer_read(buffer,buffer_u32);
        if instance_exists(obj_slave)
        {
            with(obj_slave)
            {
                if playerName = other.name
                {
                    mouse_x  =  other.xxx;  //not allowed
                    mouse_y  =  other.yyy;  //not allowed
                
                }
            }
        }
        break;
(This is in a client_Receive packet script)

This is also from a 'Key Pressed' script:
Code:
buffer_seek(CLIENT.client_buffer,buffer_seek_start,0);
buffer_write(CLIENT.client_buffer,buffer_u8, argument0);
buffer_write(CLIENT.client_buffer,buffer_u32, argument1);


buffer_write(CLIENT.client_buffer,buffer_u32, x);
buffer_write(CLIENT.client_buffer,buffer_u32, y);

buffer_write(CLIENT.client_buffer,buffer_u32, mouse_x);//added this here, because it felt right
buffer_write(CLIENT.client_buffer,buffer_u32, mouse_y);//added this here, because it felt right


I am getting an error because mouse_x and y are READ ONLY, while the X and Y of the movements are non-read only. How do I have to change the logic around to accommodate for this?
 
Last edited by a moderator:

TailBit

Member
Maybe try using:
Code:
window_mouse_set(x, y);
but that would make everyone connected have their mouse position moved to that user's mouse position.. so you might want to remember the old position then change it, trigger the click event, then change it back..

I would just make each slave have a set of variables that tell where it last pressed, that way you can draw the mouse position for everyone connected if you wish.

Code:
if instance_exists(obj_slave)
{
    with(obj_slave){
        ...
    }
}
I see you do instance_exists(obj) around with(obj) .. this is not nessesary, as with(obj) will not trigger if obj doesn't exist .. so with kinda work like instance_exists in a way.
 
C

Carcophan

Guest
this is not nessesary, as with(obj) will not trigger if obj doesn't exist .. so with kinda work like instance_exists in a way.
Interesting, thanks. Is this still the case when I want to check if a slave/client exists, then go through each of them to check each of them (assuming there are more than 2)? I assumed the with() logic would address that.


I would just make each slave have a set of variables that tell where it last pressed, that way you can draw the mouse position for everyone connected if you wish.
This is kind of what I am trying to do - i think.

The client has a ds_grid/map that has some interaction to it, so knowing where each players mouse click is, each step, is critical. I am just having a hard time to figure that out.
 
C

Carcophan

Guest
I think I can boil it down to: "How can I get this line to trigger in someone else's client, when I left click a tile in my client - "ds_grid_set(global.gridName, i, j, 0);". Can it be sent in the same way as a keypress key release call?


case KEY_RELEASE:
name = buffer_read(buffer,buffer_string);
key = buffer_read(buffer,buffer_u32);
xx = buffer_read(buffer,buffer_u32);
yy = buffer_read(buffer,buffer_u32);
 
Top