Results 1 to 8 of 8

Thread: Writing to files

  1. #1
    Join Date
    Aug 2007
    Location
    Emo-land
    Posts
    1,109
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Writing to files

    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...

    SCAR Code:
    //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:
    Quote Originally Posted by 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
    <> <****************************************>
    Quote Originally Posted by 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.

  2. #2
    Join Date
    Sep 2006
    Location
    include srl/srl.scar ( aussie)
    Posts
    2,875
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  3. #3
    Join Date
    Aug 2007
    Location
    Emo-land
    Posts
    1,109
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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

  4. #4
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  5. #5
    Join Date
    Oct 2006
    Posts
    1,190
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    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



  6. #6
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by FrÕzÑ_§ÕµL View Post
    SCAR Code:
    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.

    Rep++ for you.

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

  7. #7
    Join Date
    Aug 2007
    Location
    Emo-land
    Posts
    1,109
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Lol nice work zeph 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

  8. #8
    Join Date
    Aug 2007
    Location
    Emo-land
    Posts
    1,109
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

    SCAR Code:
    //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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 02-16-2009, 10:12 AM
  2. File Writing
    By Metagen in forum OSR Help
    Replies: 7
    Last Post: 08-04-2008, 05:47 PM
  3. Do you like writing?
    By lakerzz8 in forum Discussions & Debates
    Replies: 3
    Last Post: 02-24-2008, 08:23 PM
  4. C++: Writing and reading files
    By Repentinus in forum C/C++ Help and Tutorials
    Replies: 3
    Last Post: 11-11-2007, 04:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •