Jump to content


Photo

Client network obj gets ruined after spawning an item

gm:studio

Best Answer JesterOC, 24 February 2016 - 04:23 AM

SOLVED IT MYSELF  :lol: 

here's what was wrong:
if instance_exists(global.serveitems[IDis,0]) {
    itemIS = global.serveitems[IDis,0] 
    with itemIS {instance_destroy()}
    global.serveitems[IDis,0] = -1
    global.serveitems[IDis,1] = -1
    global.serveitems[IDis,2] = 1
    }
 
Here's how it is now: 
if global.serveitems[IDis,0] != -1 {
    itemIS = global.serveitems[IDis,0] 
    with itemIS {instance_destroy()}
    global.serveitems[IDis,0] = -1
    global.serveitems[IDis,1] = -1
    global.serveitems[IDis,2] = 1
    }

(apparently instance_exists(-1) breaks the network object) so instead i just check if the array index == -1

Go to the full post


  • This topic is locked This topic is locked
2 replies to this topic

#1 JesterOC

JesterOC

    GMC Member

  • GMC Member
  • 73 posts
  • Version:GM:Studio

Posted 24 February 2016 - 12:59 AM

So on client side when a mushroom is destroyed by the player object it uses the following script to create an item of the input "type"
 

///scr_serve_item_to_server(x,y,type,amount,level)


itemserve1 = buffer_create(256, buffer_grow, 1)
    buffer_write(itemserve1, buffer_s16, 39);
    buffer_write(itemserve1, buffer_s16, argument0);
    buffer_write(itemserve1, buffer_s16, argument1);
    buffer_write(itemserve1, buffer_s8, argument2);
    buffer_write(itemserve1, buffer_s8, argument3);
    buffer_write(itemserve1, buffer_s8, argument4);
    network_send_packet(global.connection, itemserve1, buffer_get_size(itemserve1));
    buffer_delete(itemserve1)
//end data send

It gets to the server at the following case in the server object, where it is send back to the player(s) to create the item:

case 39: //Player has served up an item
    chat_addLine("recieved player serving item", c_fuchsia)
    var sock = ds_map_find_value(async_load, "id");
    var spaceat2 = -1;
    with obj_client {if socket == sock {spaceat2 = self.space}} 
    var IDis = scr_get_item_ID()
    var xxis = buffer_read(buffer, buffer_s16)
    var yyis = buffer_read(buffer, buffer_s16)    
    var typis = buffer_read(buffer, buffer_s8)
    var amtis = buffer_read(buffer, buffer_s8)
    var lvlis = buffer_read(buffer, buffer_s8)
    if IDis != -1 and spaceat2 != -1{
    thisitem = scr_create_item_type(xxis,yyis,typis,spaceat2,IDis,lvlis,amtis)
     //set item array
    global.serveitems[IDis,0] = thisitem //obj
    global.serveitems[IDis,1] = typis //type
    global.serveitems[IDis,2] = lvlis //lvl
    
    
     //send to space
    var i3msg = buffer_create(256, buffer_grow, 1);
    // Write the package ID
    buffer_write(i3msg, buffer_s16, 34);
    // Write the stuff
    buffer_write(i3msg, buffer_s16, IDis);
    buffer_write(i3msg, buffer_s16, xxis);
    buffer_write(i3msg, buffer_s16, yyis);
    buffer_write(i3msg, buffer_s8, typis);
    buffer_write(i3msg, buffer_s8, amtis);
    buffer_write(i3msg, buffer_s8, lvlis);
    // Send the buffer
    send_toSpaceHouse(i3msg,spaceat2,-1); //send to space
    // Delete the buffer
    buffer_delete(i3msg);
    
    }
    
    break;   

 

The client's network object receives the item spawn and creates it.

case 34:
    var IDis = buffer_read(buffer, buffer_s16)
    var xxis = buffer_read(buffer, buffer_s16)
    var yyis = buffer_read(buffer, buffer_s16)
    var typis = buffer_read(buffer, buffer_s8)
    var amtis = buffer_read(buffer, buffer_s8)
    var lvlis = buffer_read(buffer, buffer_s8)
    
    if instance_exists(global.serveitems[IDis,0]) {
    itemIS = global.serveitems[IDis,0] 
    with itemIS {instance_destroy()}
    global.serveitems[IDis,0] = -1
    global.serveitems[IDis,1] = -1
    global.serveitems[IDis,2] = 1
    }
    //create item
    it = scr_create_item_type(xxis,yyis,typis,global.space,IDis,lvlis,amtis)
    global.serveitems[IDis,0] = it
    global.serveitems[IDis,1] = it.type
    global.serveitems[IDis,2] = it.lvl
    
    break;

NOW HERE'S WHERE IT GETS WEIRD... 
It creates the spawned object correctly, but then afterwards the majority of my network cases stop working...
Enemys don't turn around like they are supposed to, can't create o_slash obj to attack anymore...
Really weird... the doors still work.... 


I already tried looking over the code for about 3 hours... 
Checked that breaks were used properly...
Did some debugging... found that it happens when the client spawns the object. so it makes it through the server part,

meaning it has to be an error in the clients network obj?
EDIT: SO I DID SOME MORE DEBUGGING, AND =THE SERVER TO CLIENT STUFF STOPS WORKING AFTER THE ITEM SPAWN=...

I'm stumped, If anybody knows what might be wrong or you want me to post more code let me know...
Thanks in advance, JesterOC


Edited by JesterOC, 24 February 2016 - 04:05 AM.

  • 0

Check out Jester OC Games on Facebook or on GameJolt

:lol:  :lol:  :lol:

Check out my new game "HOTEL WONDERLAND
:wub:


#2 JesterOC

JesterOC

    GMC Member

  • GMC Member
  • 73 posts
  • Version:GM:Studio

Posted 24 February 2016 - 04:23 AM   Best Answer

SOLVED IT MYSELF  :lol: 

here's what was wrong:
if instance_exists(global.serveitems[IDis,0]) {
    itemIS = global.serveitems[IDis,0] 
    with itemIS {instance_destroy()}
    global.serveitems[IDis,0] = -1
    global.serveitems[IDis,1] = -1
    global.serveitems[IDis,2] = 1
    }
 
Here's how it is now: 
if global.serveitems[IDis,0] != -1 {
    itemIS = global.serveitems[IDis,0] 
    with itemIS {instance_destroy()}
    global.serveitems[IDis,0] = -1
    global.serveitems[IDis,1] = -1
    global.serveitems[IDis,2] = 1
    }

(apparently instance_exists(-1) breaks the network object) so instead i just check if the array index == -1


  • 0

Check out Jester OC Games on Facebook or on GameJolt

:lol:  :lol:  :lol:

Check out my new game "HOTEL WONDERLAND
:wub:


#3 GameGeisha

GameGeisha

    GameGeisha

  • GMC Member
  • 6565 posts
  • Version:GM:Studio

Posted 28 February 2016 - 06:55 PM

-1 is the value of self, and by definition instance_exists(self) is always true if it gets to be evaluated.

 

Next time, initialize variables for holding instance or object IDs to noone (-4), not -1.

 

GameGeisha


Edited by GameGeisha, 28 February 2016 - 06:55 PM.

  • 1
Latest Releases:
  • GMLinear --- Matrix and vector math in one line!
  • GMAssert --- Debug invalid values and write quick unit tests with ease!
  • KameGMS --- Bring up TortoiseSVN and TortoiseGit dialogs from within the GMS IDE!
  • JSOnion v1.1 --- The stink-free way to handle JSON! (even deeply nested ones)





Also tagged with one or more of these keywords: gm:studio