Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - n0_0ne

Pages: [1]
1
Network / Little Online Highscore
« on: April 06, 2009, 10:42:41 am »
Hello,
I'm a totally beginner, when it comes to network and files, so I am having some trouble setting up a online highscore for my game.
I imagined a little protocol with a Int8 at the beginning of each packet, to identify what sort of packet it is (close server, insert new highscore, send highscorelist etc...)... this works somehow...
To test a little bit, I wanted the server to write a new entry into a file, then reading it, creating a std::list with all entries, and then writing all list-entries into std::cout...
Let me first post my code:
Code: [Select]

string sName;
float fScore;
// Read Packet into vars
PacketReceived >> sName >> fScore;

// Open file
fstream ScoreFile("highscore.txt", ios::in | ios::out | ios::binary);
if (ScoreFile.is_open())
cout << "Opened ScoreFile" << endl;

// Create Entry of packet
entry Entry;
Entry.Name = sName;
Entry.Score = fScore;

// Set writepointer to end
ScoreFile.seekp(0, ios::end);

// Write entry into file
ScoreFile << Entry.Name << Entry.Score;
cout << Entry.Name << ": " << Entry.Score << " inserted" << endl;

ScoreFile.seekp(0, ios::beg);
// Create a highscorelist
list<entry> Entries;
while (!ScoreFile.eof())
{
entry Entry;
ScoreFile >> Entry.Name;
ScoreFile >> Entry.Score;
Entries.push_back(Entry);
}

// Write list
cout << endl << "Begin new highscorelist:" << endl;
list<entry>::iterator It = Entries.begin();
while (It != Entries.end())
{
cout << It->Name << ": " << It->Score << endl;
It++;
}

ScoreFile.close();
cout << "Closed ScoreFile" << endl;

///////////////////////////////
// this is the entry struct:
struct entry
{
    string Name;
    float Score;
};

OK, this writes a new entry into the file (at the end), but I am not able to read it in the way I want to...
My std::list will always have only 1 entry, where the entry.Name (which is a string) contains the whole file (xtimes string+float), and a weird entry.Score = -1.9xxxxx. It seems, that the strings aren't zeroterminated, so he will always read the whole file into to entry.Name.

What am I doing wrong?

Edit: I found a way how to do it, just insert a ' ' (space) between string and float... so File >> string will only read until the space and stop!

2
General discussions / Key recognition bug
« on: April 04, 2009, 11:59:46 am »
Ok I tested it again in a text editor... you were right, this error occurs there, too. I couldn't imagine and never realized, that my keyboard is that limited...

Sorry Laurent, that I doubted your incredible skillZ :D

3
General discussions / Key recognition bug
« on: April 04, 2009, 11:34:15 am »
It's a laptop so I can't use another keyboard that easy ^^
But in case of this matrix... Left is in the same row as Space... but Right is too, and it works... Can nobody just test these three keys with a normal usb keyboard?

4
General discussions / Key recognition bug
« on: April 04, 2009, 10:52:38 am »
Yeah, that was also my first thought... but it works for example with Up+Right+Space... and I think there isn't a big difference between Right and Left arrows in my keyboard... So I thought it must be a problem inside SFML.

Edit: I tested a bit more... it seems, that there really is a problem with Left+Up+Space, if you press two of them, the third key won't be recognized anymore... but if I press Down instead of Up, or Right instead of Left, everything is fine.  :?:

5
General discussions / Key recognition bug
« on: April 04, 2009, 10:28:36 am »
Hello,
I think I found a little bug in the sf::Input class.
In my project IsKeyDown(sf::Key::Space) works fine, only in combination with sf::Key::Left + sf::Key::Up pressed, it will always return false. I don't think that I am doing anything wrong. Perhaps someone else could test it.
If it's really a bug, I hope it will be fixed in the next release :)

Pages: [1]
anything