Interesting problem with 2d online game

Advanced game related topics
ewardd
User
User
Posts: 33
Joined: Tue Jul 16, 2013 12:28 pm

Interesting problem with 2d online game

Post by ewardd »

Hello everyone.

I have interesting problem with online game. Just simple 2d game. Everything works fine, but sometimes client getting error on bullet moving. As i think this happens because it wants to move bullet, but bullet, in this time, was deleted (I have Thread which accept server commands - like delete bullet). So in time it wants to add to bullet position its speed, bullets getting deleted from server and this cause error.

Do you guys have any ideas how can i fix this? Or can be there an another problem?
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Interesting problem with 2d online game

Post by Demivec »

ewardd wrote:Do you guys have any ideas how can i fix this? Or can be there an another problem?
It would be nice if you gave some more information. Things that would be helpful: a brief description of the simple 2d game, a screen capture of the game being played, or some details of the server commands that are processed.

You could solve the problem of 'moving a deleted bullet' by first checking to see if it exists first.
ewardd
User
User
Posts: 33
Joined: Tue Jul 16, 2013 12:28 pm

Re: Interesting problem with 2d online game

Post by ewardd »

Simplest game - moving ur own space ship using WASD and shot using mouse button. Server sends things like position of every player, their mouse position and sends command for deleting bullet if needs. Everything works good but sometimes game crashing with error on moving bullet. Bullet()\X+Bullet()\SpeedX. It is in a loop for every bullet. I dont know how to check if element exist without using this element. It looks like Game Process trying to move bullet which one, in this time, getting deleted from Network Thread (by server command - simple text with bullet id to delete it).
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Interesting problem with 2d online game

Post by Demivec »

ewardd wrote:It is in a loop for every bullet. I dont know how to check if element exist without using this element. It looks like Game Process trying to move bullet which one, in this time, getting deleted from Network Thread (by server command - simple text with bullet id to delete it).
Is the 'bullet id' a pointer to the list element (in Bullet())? If it is you will need a more elaborate way to check if an element exists. Perhaps using a map datatype. You could place the id of elements that exist in the map and then check it to see if an id is in the map before you try to access it. When you delete the bullet you would also delete the map element for the corresponding id.

Going through each element of the list in a loop should not cause an error. If a bullet has been deleted it will not be a part of the loop anymore. There must be something more to this. Is the 'bullet id' used for other things besides deleting a bullet?
ewardd
User
User
Posts: 33
Joined: Tue Jul 16, 2013 12:28 pm

Re: Interesting problem with 2d online game

Post by ewardd »

Bullet()\ID is used just for searching this bullet latter for any things... on example deleting it.
ewardd
User
User
Posts: 33
Joined: Tue Jul 16, 2013 12:28 pm

Re: Interesting problem with 2d online game

Post by ewardd »

Uh. Soloved problem. I just created an new list and when server sends command for deleting bullet it writes bullet id in this new list. In game loop, at end, it uses this list to delete bullets.
Post Reply