• 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!

send_packet doesn't work in for loop

S

superm1ch0

Guest
Hello,

I have a problem with the send_packet function, I want to loop trough an array and send a packet when a value is equal to 1. This is my code:

Code:
///Loop door de unit queue

for(var i = 0; i < array_height_2d(global.unit_queue); i++) {
    if(global.unit_queue[i, 0] == 1) {
        buffer_seek(global.tcp_buffer, buffer_seek_start, 0);
        buffer_write(global.tcp_buffer, buffer_u8, global.SEND_CREATE_UNIT_MSG);
        network_send_packet(global.socket[0], global.tcp_buffer, buffer_tell(global.tcp_buffer));
       
        show_message("Test");
       
        //Maak de queue leeg
        global.unit_queue[i, 0] = noone;
        global.unit_queue[i, 1] = noone;
    }
}
The problem is that it shows the message box "Test" so I'm sure that the if statement is true but it doesn't send the packet to a socket.
When I do this:

Code:
///Loop door de unit queue

for(var i = 0; i < array_height_2d(global.unit_queue); i++) {
    if(global.unit_queue[i, 0] == 1) {
        //Maak de queue leeg
        global.unit_queue[i, 0] = noone;
        global.unit_queue[i, 1] = noone;
    }
}

buffer_seek(global.tcp_buffer, buffer_seek_start, 0);
buffer_write(global.tcp_buffer, buffer_u8, global.SEND_CREATE_UNIT_MSG);
network_send_packet(global.socket[i], global.tcp_buffer, buffer_tell(global.tcp_buffer));
With this code he sends the packet now every frame (Because it's in a step event). But if I put this code into the if statement he doesn't.

Does anyone know how to fix this?
 
S

superm1ch0

Guest
Oh sorry it must be global.socket[0], I copied that piece of code but it has to work.
 
Top