Author Topic: How to write?  (Read 1651 times)

0 Members and 1 Guest are viewing this topic.

Offline rOy

  • Soldier
  • **
  • Posts: 120
How to write?
« on: January 06, 2013, 12:15:48 am »
hello i need help with one script

I Have a problem with this

Code: [Select]
procedure OnJoinGame(ID, Team: byte);
var
    i:byte;
begin
if not FileExists('scripts/asd' +CurrentMap+ '.log') then WriteFile('scripts/asd' +CurrentMap+ '.log');
if not FileExists('scripts/asd' +lowercase(player+) '.log') then WriteFile('scripts/asd' +lowercase(player)+ '.log');
end;

Why doesn't work?

To write .log files

Script is a separate

Files free
Files.log only

Thanks for the advice

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: How to write?
« Reply #1 on: January 06, 2013, 07:19:19 pm »
The event OnJointGame specifies the id of the player joining the game. It appears you are trying to write to a file containing the name of the player, however the variable player does not exist. You will need to get the name of the player with the id ID. In this code, I define such a variable and assign it to be the name of the player. Also, you have a misplaced the + character in the second if statement line in 'scripts/asd' +lowercase(player+) '.log'.

procedure OnJoinGame(ID, Team: byte);
var
    i:byte;
    player:string;
begin
player := GetPlayerStat(ID, 'name');
if not FileExists('scripts/asd' +CurrentMap+ '.log') then WriteFile('scripts/asd' +CurrentMap+ '.log', 'dummy text');
if not FileExists('scripts/asd' +lowercase(player)+ '.log') then WriteFile('scripts/asd' +lowercase(player)+ '.log', 'dummy text');
end;

I did not test this code.
« Last Edit: January 07, 2013, 08:09:15 pm by DorkeyDear »

Offline Tehbugerz0r

  • Soldier
  • **
  • Posts: 158
Re: How to write?
« Reply #2 on: January 07, 2013, 06:10:17 am »
Writefile has two parameters: function WriteFile(FileName, Data: string): boolean;
You could use WriteFile('scripts/asd' +CurrentMap+ '.log', ''); to write nothing(probably), but there's no real point in doing so.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: How to write?
« Reply #3 on: January 07, 2013, 08:08:51 pm »
Woops you are right Tehbugerz0r; I did not notice, rOy, you forgot the second argument/parameter to WriteFile. I edited my previous code to include some dummy text. It now should write 'dummy text' (without quotes) to both files.

Offline rOy

  • Soldier
  • **
  • Posts: 120
Re: How to write?
« Reply #4 on: January 08, 2013, 09:03:35 pm »
The event OnJointGame specifies the id of the player joining the game. It appears you are trying to write to a file containing the name of the player, however the variable player does not exist. You will need to get the name of the player with the id ID. In this code, I define such a variable and assign it to be the name of the player. Also, you have a misplaced the + character in the second if statement line in 'scripts/asd' +lowercase(player+) '.log'.

procedure OnJoinGame(ID, Team: byte);
var
    i:byte;
    player:string;
begin
player := GetPlayerStat(ID, 'name');
if not FileExists('scripts/asd' +CurrentMap+ '.log') then WriteFile('scripts/asd' +CurrentMap+ '.log', 'dummy text');
if not FileExists('scripts/asd' +lowercase(player)+ '.log') then WriteFile('scripts/asd' +lowercase(player)+ '.log', 'dummy text');
end;

I did not test this code.

DorkeyDear nice release but I need only:
That form only free files.
Example: I've nick rOy and Current map is ctf_Ash
And I join the game (maybe without logs) Must create free logs (map and player Name)
I've a question may be example IDToName(i) ? + GetPlayerStat ?

I don't want to write to 'dummy.txt'

Thanks for help
« Last Edit: January 08, 2013, 09:08:13 pm by rOy »

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: How to write?
« Reply #5 on: January 11, 2013, 03:54:03 pm »
Currently, it would NOT write to the file dummy.txt. The way it is now is it will try to write to two files (if they do not already exist): scripts/asdMapName.log and scripts/asdplayername.log (where the underlined stuff would be variable). The content of the file will be "dummy text" (without quotes). That can be easily changed in the script (look for the part that says 'dummy text' and change what is between the ' single quote marks ' ). If you want the files to be blank (no content), have no text there (simply ''; two consecutive single quote marks).

Regarding your question of IDToName vs GetPlayerStat, I do not know. I think IDToName is still implemented, but as far as I know, it is not preferred, and I always thought of it as depreciated. I could be wrong about this though, and am not completely certain.

Offline rOy

  • Soldier
  • **
  • Posts: 120
Re: How to write?
« Reply #6 on: January 11, 2013, 11:33:17 pm »
Currently, it would NOT write to the file dummy.txt. The way it is now is it will try to write to two files (if they do not already exist): scripts/asdMapName.log and scripts/asdplayername.log (where the underlined stuff would be variable). The content of the file will be "dummy text" (without quotes). That can be easily changed in the script (look for the part that says 'dummy text' and change what is between the ' single quote marks ' ). If you want the files to be blank (no content), have no text there (simply ''; two consecutive single quote marks).

Regarding your question of IDToName vs GetPlayerStat, I do not know. I think IDToName is still implemented, but as far as I know, it is not preferred, and I always thought of it as depreciated. I could be wrong about this though, and am not completely certain.

Hey
I understand you.

I've a test
This
Code: [Select]
procedure OnJoinGame(ID, Team: byte);
var
    i:byte;
    player:string;
begin
player := GetPlayerStat(ID, 'name');
if not FileExists('scripts/asd' +CurrentMap+ '.log') then WriteFile('scripts/asd' +CurrentMap, '.log');
if not FileExists('scripts/asd' +lowercase(player)+ '.log') then WriteFile('scripts/asd' +lowercase(player)+ GetPlayerStat, '.log');
end;

where's the problem?
Log say:
asd -> [Error] (9:123): Invalid number of parameters

If have change (,)

Code: [Select]
procedure OnJoinGame(ID, Team: byte);
var
    i:byte;
    player:string;
begin
player := GetPlayerStat(ID, 'name');
if not FileExists('scripts/asd' +CurrentMap+ '.log') then WriteFile('scripts/asd' +CurrentMap '.log');
if not FileExists('scripts/asd' +lowercase(player)+ '.log') then WriteFile('scripts/asd' +lowercase(player)+ GetPlayerStat '.log');
end;

Log say:
asd -> [Error] (8:95): comma (',') expected
the script does't know where to write (logic)

But it is written that (on script CurrentMap and Player)
Why not writting?

Script name is: asd

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: How to write?
« Reply #7 on: January 12, 2013, 03:12:31 am »
I've a test
This
Code: [Select]
procedure OnJoinGame(ID, Team: byte);
var
    i:byte;
    player:string;
begin
player := GetPlayerStat(ID, 'name');
if not FileExists('scripts/asd' +CurrentMap+ '.log') then WriteFile('scripts/asd' +CurrentMap, '.log');
if not FileExists('scripts/asd' +lowercase(player)+ '.log') then WriteFile('scripts/asd' +lowercase(player)+ GetPlayerStat, '.log');
end;

where's the problem?
Log say:
asd -> [Error] (9:123): Invalid number of parameters
Quote
if not FileExists('scripts/asd' +lowercase(player)+ '.log') then WriteFile('scripts/asd' +lowercase(player)+ GetPlayerStat, '.log');
The issue is with your GetPlayerStat. If you wanted to put the player's name at that point there, have it be GetPlayerStat(ID, 'name') or player. Keep is mind GetPlayerStat is a function, similar to how WriteFile is a function, it takes 2 parameters/arguments. However, we already stored the name of the player in a variable called player, which I see you are using here lowercase(player) before the GetPlayerStat. We therefore do not need the GetPlayerStat part there at all.

You removing the comma from the code shows me you do not know the logic or structure of what is going on. I can't really teach this very easily.

Code: [Select]
procedure OnJoinGame(ID, Team: byte);
var
    i:byte;
    player:string;
begin
player := GetPlayerStat(ID, 'name');
if not FileExists('scripts/asd' +CurrentMap+ '.log') then WriteFile('scripts/asd' +CurrentMap, '.log');
if not FileExists('scripts/asd' +lowercase(player)+ '.log') then WriteFile('scripts/asd' +lowercase(player), '.log');
end;
WriteFile is a function which takes two inputs. The first argument is for the filename of what file to write to, and the second is the contents of that file: WriteFile('filename.txt', 'content') will write the text content to the file filename.txt. The second argument of WriteFile, which is the file contents, will be the text content. In your problem, the first argument for WriteFile is dependent on other stuff; the player name is dynamic. The filename is going to be the result of this code: 'scripts/asd' +lowercase(player)+ '.log'. The second argument of WriteFile, which is the file contents, will be the text .log.
« Last Edit: January 12, 2013, 03:15:52 am by DorkeyDear »

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: How to write?
« Reply #8 on: January 12, 2013, 05:26:05 am »
Curt: You may filter out invalid filename characters to avoid problems, but would probably confuse him :P (and include a little bit of work i never liked)

r0y: Check this out if you haven't. It's worth it.
« Last Edit: January 12, 2013, 05:27:57 am by Swompie »