SRL Archive - OSR Help

Writing to files


FrÕzÑ_§ÕµL

2008-03-09 00:59:34

Hi,
my problem is that chr(13) isn't being written to files. I believe this may be due to srl changing chr(13) to chr(10) when using SMART. So I'll shove some code in for you to see what I'm writing…

//In Setup;
if FileExists(ScriptPath + 'Forest Frostbite Report.txt') then
Begin
x := OpenFile(ScriptPath + 'Forest Frostbite Report.txt', false);
ReadFileString(x, s, FileSize(x));
CloseFile(x);
end;
Fr0znFile := RewriteFile(ScriptPath + 'Forest Frostbite Report.txt', false);
if s <> '' then
WriteFileString(Fr0znFile, s + CHR(13));
WriteFileString(Fr0znFile, TheDate(1) + ', ' + TheTime + CHR(13));

//In PlayerReport (unfinished)
WriteFileString(Fr0znFile, CHR(13));
WriteFileString(Fr0znFile,'<> <****************************************>' + CHR(13));
WriteFileString(Fr0znFile,'<> <* Forest Frostbite <***> by FrÕzÑ_§ÕµL *>' + CHR(13));
WriteFileString(Fr0znFile,'<> <****************************************>' + CHR(13));
WriteFileString(Fr0znFile,'<> <* Gained ' + IntToStr(LevelsGained) + ' Levels' + CHR(13));
WriteFileString(Fr0znFile,'<> <* Done ' + IntToStr(LoadsDone) + ' Loads of ' + Tree + #39 + 's' + CHR(13));
WriteFileString(Fr0znFile,'<> <* Chopping ' + IntToStr(Round(LoadsDone*100*27/(GetTimeRunning*100/3600000))) + ' ' + Tree + ' Logs Per Hour' + CHR(13));
WriteFileString(Fr0znFile,'<> <* ' + IntToStr(ActivePlayers) + ' Players Active After ' + TimeRunning + CHR(13));
WriteFileString(Fr0znFile,'<> <****************************************>');
//gap
for i := 0 to HowManyPlayers - 1 do
if (Players[i].Rand <> '') and Not(Players[i].Active) then
Begin
WriteFileString(Fr0znFile,'<> Players' + #39 + ' Status : ');
Writeln('<> Players' + #39 + ' Status : ');
Break;
end;
for i := 0 to HowManyPlayers - 1 do
if Not(Players[i].Active) and (Players[i].Rand <> '') then
Begin
WriteFileString(Fr0znFile, '<> ' + Capitalize(Players[i].Name) + ' - ' + Players[i].Rand + '. (Level ' + IntToStr(Players[i].Integers[2]) + ' Woodcutting)');
Writeln('<> ' + Capitalize(Players[i].Name) + ' - ' + Players[i].Rand + '. (Level ' + IntToStr(Players[i].Integers[2]) + ' Woodcutting)');
end;

So yea, get some ideas from that if you like, but anyway, the .txt turns out as:
From: Making a Liar of Me
March 9th, 2008 06:37:11 PM

<> <****************************************>
<> <* Forest Frostbite <***> by FrÕzÑ_§ÕµL *>
<> <****************************************>
<> <* Gained 0 Levels
<> <* Done 1 Loads of Willow's
<> <* Chopping 450 Willow Logs Per Hour
<> <* 6 Players Active After 3 Minutes and 48 Seconds
<> <****************************************>


From: The Reality
March 9th, 2008 06:37:11 PM<> <****************************************><> <* Forest Frostbite <***> by FrÕzÑ_§ÕµL *><> <****************************************><> <* Gained 0 Levels<> <* Done 1 Loads of Willow's<> <* Chopping 450 Willow Logs Per Hour<> <* 6 Players Active After 3 Minutes and 48 Seconds<> <****************************************>


Yea ok that looks normal now, but in notepad it only looks like that if you compress the sides. What if I want it normal when maximized?! Two chr(13)s? 3?! wtf there must be a way!

Thank you to all who read my ramblings and participate in my problem.

NiCbaZ

2008-03-09 01:08:43

o0o you doing this thats awesome sorry i dont know how to help but i will be good if you get this to work i always forget to save progs and your scripts are the only ones i use so good luck.

FrÕzÑ_§ÕµL

2008-03-09 01:10:12

Yea lol, I'm mainly doing it for you, but my computer is always over heating while I'm at school, so it'll be good to have em saved. I will eventually get it so it replaces the proggy in the file under this session, and all the ones from previous sessions will stay on there until deleted by user :)

mixster

2008-03-09 06:07:43

Try opening with wordpad/other text editor as I always have the issue with my enter's coming up as those dodgy unrecognised character rectangles in notepad, but came out ok in other things. Otherwise, I'm pretty sure SMART automatically changes chr(13) to chr(10) so I doubt it would be that, but you could try. It may be worth finding out how notepad's store enter's (as /r or /r/n etc.) to see if scar offers a way to enter those, but I'm not sure about that bit.
Edit: As an afterthought, it may be worth saving it as an ini since there are only a few people who will actually read it outside, whihc would also mean you could then use previous proggies.

Bonfield

2008-03-09 06:19:06

good job i was looking for something like this when i was trying to add multiplayer to my forms and there wasnt much ou there execpt SRLs playerform thanks this really helped me

ZephyrsFury

2008-03-09 06:46:21

From: FrÕzÑ_§ÕµL


ReadFileString(x, s, FileSize(x));


OMG…. You don't know how long I've been trying to find a procedure that returns the size of the file. :duh:

Rep++ for you. :D

EDIT: WTF its been in the SCAR manual the whole time. I'm such a noob…. Gah.. :fiery:

FrÕzÑ_§ÕµL

2008-03-09 13:52:14

Lol nice work zeph :p yea I always read the SCAR manual, read the entire thing probably about 5 times.

Thanks Mixster you have been very helpful, but I don't have wordpad lol ^^ a

FrÕzÑ_§ÕµL

2008-03-09 23:31:52

I'll put my finished code here for anyone that wants to see. I used GetDebugText and copied the report from the debug box because it includes spaces and so when I write the part of it I need to the file it turns out fine.

//In Setup
s := '';
if FileExists(ScriptPath + 'Forest Frostbite Report.txt') then
Begin
Fr0znFile := OpenFile(ScriptPath + 'Forest Frostbite Report.txt', false);
ReadFileString(Fr0znFile, s, FileSize(Fr0znFile));
CloseFile(Fr0znFile);
end;
Fr0znFile := RewriteFile(ScriptPath + 'Forest Frostbite Report.txt', false);
if s <> '' then
WriteFileString(Fr0znFile, s);
WriteFileString(Fr0znFile, TheDate(1) + ', ' + TheTime + ' ');
CloseFile(Fr0znFile);

//In ProgressReport
Fr0znFile := OpenFile(ScriptPath + 'Forest Frostbite Report.txt', false);
ReadFileString(Fr0znFile, s, FileSize(Fr0znFile));
CloseFile(Fr0znFile);
Fr0znFile := RewriteFile(ScriptPath + 'Forest Frostbite Report.txt', false);
Delete(s, LastPos(TheDate(1), s) + Length(TheDate(1)) + Length(TheTime) + 3, Length(s));
DebugText := GetDebugText;
DebugText := Copy(DebugText, LastPos('<> <* Forest', DebugText) - 55, Length(DebugText));
Insert(DebugText, s, Length(s));
WriteFileString(Fr0znFile, s);
CloseFile(Fr0znFile);

Steps script undergoes:
(In Setup)
1. If file exists then opens it and copies progress reports from previous sessions.
2. Creates the file, opening it for editing and pasting in the old progress reports if there were any. Writes todays date and time at start of session.
(In Report)
3. Stores text of file in variable 's'
4. Deletes all text after todays date (erases the progress report from last load)
5. Gets the text in debug box.
6. Copies the newest report from debug box to variable 'debug'
7. Inserts the text from 'debug' into the end of 's'
8. Writes 's' to file. S will contain previous sessions reports and also the newest one from the current session.

Hope that will help anyone else having problems!