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?
Interesting problem with 2d online game
Re: Interesting problem with 2d online game
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.ewardd wrote:Do you guys have any ideas how can i fix this? Or can be there an another problem?
You could solve the problem of 'moving a deleted bullet' by first checking to see if it exists first.
Re: Interesting problem with 2d online game
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).
Re: Interesting problem with 2d online game
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.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).
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?
Re: Interesting problem with 2d online game
Bullet()\ID is used just for searching this bullet latter for any things... on example deleting it.
Re: Interesting problem with 2d online game
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.