SRL Archive - Help and Support

Saving to text file.


BobboHobbo

2009-07-29 14:19:14

I want to save text from my script to a text file, with the account information for the tutoiral runner into the SCAR folder. I can get it to work but it deletes the current text in the text file.

How can i make it keep flopping the information after each other instead of just deleting all current stuff in the file.

Thanks.

ShowerThoughts

2009-07-29 14:25:14

Read line it, put it into an array(string) then add your text to it(the array).
I haven't done it myself in Delphi but I am able to in C#.
So I can't give you an example, sorry.

Naum

2009-07-29 14:25:46

Try using OpenFile, instead of ReWriteFile :)

BobboHobbo

2009-07-29 14:27:37

From: NaumanAkhlaQ
Try using ReWriteFile, instead of OpenFile :)


procedure AddToFile;
begin
TheFile := RewriteFile(apppath +'BH - Tutorial Runner Accounts.txt', False);
try
WriteFileString(TheFile, GetDebugText);
except end;
CloseFile(TheFile);
end;

Is what i currently got.

@Herm

Theres gotta be im doing something wrong in my code ^. I dont really have so much time to spend on a stupid little account history thing.

ShowerThoughts

2009-07-29 14:29:49

Then change it to OpenFile if I understood you correctly?

Naum

2009-07-29 14:30:10

Okay, Do a ReadFileString, get that content then add it to what you have to write.

Edit: Sorry, something wrong with me, I mean't OpenFile :(

BobboHobbo

2009-07-29 14:41:33

I just tried that and nothing happens, can you post an example or something?

Naum

2009-07-29 14:46:04

Something like this:

procedure AddToFile;
Var s : string;
TheFile : Integer;
begin
TheFile := RewriteFile(apppath +'BH - Tutorial Runner Accounts.txt', False);
ReadFileString(TheFile, s, 300);
try
WriteFileString(TheFile, s+#10+#13+GetDebugText);
except end;
CloseFile(TheFile);
end;

However, this may not do what you want it to do, you might want to edit the text length.

BobboHobbo

2009-07-29 15:02:05

It works but, i also get alot of jibirish with it also >.<

;
MaxDist := 15;
Color := 2047847;
HueMod := 0.43;
SatMod := 3.23;
LumTol := 8;
MinR := 85; MaxR := 129;
MinG := 28; MaxG := 94;
MinB := 9; MaxB := 63;
MinX := 4.31; MaxX := 11.23;
MinY := 2.86; MaxY := 11.51;
MinZ := 0.59; MaxZ := 6.20;li
(ܹ
8 |Îq
   äÎ\²ú  S ou


Is above what is meant to be.

Naum

2009-07-29 15:14:55

From: BobboHobbo
It works but, i also get alot of jibirish with it also >.<



Is above what is meant to be.


Well it gives you gibberish if set the length higher than the quantity of text. Your going to have to find a way to make sure it picks the exact length from the file, either based on the progress report or the debug text :)

BobboHobbo

2009-07-29 15:19:51

Bloody never relised its so hard to paste text on a bloody text file these days.

Janilabo

2009-07-29 16:15:58

Give this a try:

procedure addTextToFile(fileLoc, text: string);
var
iFile: Integer;
s: string;
begin
if(FileExists(fileLoc))then
begin
iFile:= OpenFile(fileLoc, False);
ReadFileString(iFile, s, FileSize(iFile));
CloseFile(iFile);
if(s <> '')then
s:= (s + #13#10);
end;
iFile:= RewriteFile(fileLoc, False);
WriteFileString(iFile, (s + text));
CloseFile(iFile);
end;

begin
addTextToFile('C:\test.txt', 'test!');
end.

(Modify it to your needs :))

-Jani

EvilChicken!

2009-07-29 17:06:07

From: NaumanAkhlaQ
Well it gives you gibberish if set the length higher than the quantity of text. Your going to have to find a way to make sure it picks the exact length from the file, either based on the progress report or the debug text :)


GetFileSize(FileName: string): Int64;

If I understood correctly..

Awkwardsaw

2009-07-29 17:18:01

did you try adding all the details to an array? or multiple arrays maby for organization

n3ss3s

2009-07-29 17:22:02

Maybe you could use mixster's handy program for connections and connect a Java program to SCAR, because in Java (and C etc I think) you can just open a stream and dump your shit in it and you're done, without finding the size of the file or anything…

Janilabo

2009-07-29 17:51:17

From: n3ss3s
Maybe you could use mixster's handy program for connections and connect a Java program to SCAR, because in Java (and C etc I think) you can just open a stream and dump your shit in it and you're done, without finding the size of the file or anything…
I just tested my procedure and it added text into a file that contains 100000 lines (each line containing 1025 columns [max with my settings in Notepad], so a huge text file just for testing purposes) in 1484 ms. :p

Naum

2009-07-29 18:00:23

From: EvilChicken!
GetFileSize(FileName: string): Int64;

If I understood correctly..


Yup, BH follow mine and EC's advice and it should work :)

Janilabo

2009-07-29 18:07:33

Guys, do notice that you'll need SCAR v3.21[+] in order to use GetFileSize function (was an addition to SCAR 3.21).
My procedure (that uses FileSize function) works without problems with SCAR 3.15b[+].

But yeah, if you have 3.21[+], it is better to use GetFileSize instead of FileSize for most cases.

n3ss3s

2009-07-29 19:52:13

:mad: I never knew there was a FileSize function in 3.15…

ZaSz

2009-07-29 21:02:11

Lol, writeini = nice format anyway. Use that? You can make it write to a .txt