Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm making an online card game project but now I have a minor issue:

In my game there are rooms that users can join. How do I find out how many created rooms there are? I thought about using a static counter but it didn't work. (I thing that the reason it didn't work is because every process is run on a separated thread so using static keyword wont help me solve this problem.) Also I thought about saving it to the database but than when someone cancels a room, for others, it wont be visible.

Do you know any solution how to do this?

share|improve this question

closed as off topic by Sean Middleditch, Byte56, bummzack, Laurent Couvidou, Josh Petrie Apr 7 '13 at 3:32

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Can you elaborate a little on this comment, "Also I thought about saving it to the database but then when someone cancels a room, for others, it wont be visible." What do you mean? –  Cameron Fredman Feb 27 '13 at 21:44
When you send request to server it returns you room list. But when you get room list if someone destroy room you wont be able to see it because your list wont be updated. –  carobnodrvo Feb 28 '13 at 18:46
add comment

1 Answer 1

If it's just a handful of rooms, I'd use a flat file, otherwise you'll need to post some code of what you tried using a database... This should be a very simple request.

Here's a flat file solution. Save this as a file on your server and call it with ?do=add or ?do=sub to add or subtract the count respectively. If you don't specify do then it will print the current number-

    $new = intval(@file_get_contents("count.txt"))+1;
    $fp = fopen("count.txt", "w");
    fwrite($fp, $new);
    $new = intval(@file_get_contents("count.txt"))-1;
    if($new < 0){$new = 0;}
    $fp = fopen("count.txt", "w");
    fwrite($fp, $new);
    print @file_get_contents("count.txt");

share|improve this answer
Yea I get that but what if you want to join room you send request for online rooms and server sends you back list. Meanwhile someone cancel that room or some other people join that room you wouldn't have idea about that. –  carobnodrvo Feb 27 '13 at 22:44
Not sure what you're saying here... Instead of just recording a count, are you wanting to have a list of active rooms and then have the script to automatically count the number of active rooms? You can do this with a list of uniqueids loaded into an array. –  user1145643 Feb 28 '13 at 5:34
My room is a class and every time someone creates room it instance new class. How can other users have information about class that some other user instanced ? May be that is better formed question. –  carobnodrvo Feb 28 '13 at 11:18
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.