Author Topic: String to Integer?  (Read 751 times)

0 Members and 1 Guest are viewing this topic.

Offline royaltca

  • Major(1)
  • Posts: 5
String to Integer?
« on: July 03, 2007, 12:13:59 pm »
Hi. I want my script to load the number of kills of all players.

I am saving it:
WriteFile(pname,IntToStr(kills[ID]); - when player leaves.

when i want to read it back:
kills[ID]:=StrToInt(ReadFile(pname));   - the server return error: '9' is not an integer value... i don't know what's happend. I need convert it to integer. Please help.

Offline truup

  • Soldier
  • **
  • Posts: 243
Re: String to Integer?
« Reply #1 on: July 03, 2007, 01:34:47 pm »
Are you sure that the error is on that line? Because it seems right to me (Im not a pascal specialist though).

Anyway, making each separate file for every player might not be a good idea. You could make an array of structures, that holds the information you want, and save it in one file.

Offline royaltca

  • Major(1)
  • Posts: 5
Re: String to Integer?
« Reply #2 on: July 03, 2007, 03:13:35 pm »
The line looks to be correct. That's the simplest way i think. I can't use records, because when i use (var Plik:TextFile) the server returns error: "undeclared identifier TextFile".

I really need help. I need to save amount of kills and read it back to integer value. How to do that?

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: String to Integer?
« Reply #3 on: July 03, 2007, 03:45:54 pm »
Make it do a WriteLn of whatever text you're getting from ReadFile followed AND preceded by '=' (to make sure there's not like some weird unseen characters).  It should say =9= if it works right.
Make sure kill[ID] is an integer.

Also I recommend that you should make one file for ALL players.  Also, I would make it write the player's IP as well as the player's name (so that someone else can't login with the same name and get points).  I would recommend making a .txt file called "PlayerKills.txt" and that it looks like this:

45.178.175.33
someplayer'sname
34
45.34.28.111
someoneElse
16
94.122.101.93
AnotherPlayer'sName
67


So you'll only have one file!
Also, use enter to separate each line.  Don't do 34.3.65.111-playername-23 because then if the player's name contains the character "-" then he can screw up the file (Players, I believe, can't have an enter-symbol (#13) in their name).

Hope that helps!
Can't think of anything original to put here...