I'd like to have my scripts go to an external file and pull my username, password, and pin number. What is the most efficient way to do that?
I know I probably need to use ReadINI and WriteINI but I don't know how to do that.
Thanks in advance,
JIM
I'd like to have my scripts go to an external file and pull my username, password, and pin number. What is the most efficient way to do that?
I know I probably need to use ReadINI and WriteINI but I don't know how to do that.
Thanks in advance,
JIM
Uhh.. shouldn't you know that info?![]()
I wrote a function, dont know if it works, you should try it.
SCAR Code:function ReadTheFile( PathToFile: String; I: Integer ): String;
var S: String;
F: Integer;
TheArray: Array of String;
begin
F := OpenFile( PathToFile, False );
ReadFileString( F, S, FileSize( F ) );
CloseFile( F );
TheArray := Explode( ';', S );
Result := TheArray[ I ];
end;
Should read in the file like: username;password;pin
For username I is 0, and for password it is 1, etc.
There used to be something meaningful here.
Easiest way would to be Savesetting/load setting as it's pretty fail proof, WriteCharsfile string is a kinda tricky... I'd recommend INI files as they are easy to manage and manipulate.
jimthesoundman: you could make a scar script and save it in the include folder which has this in it:
then put this in your script:Code:procedure DeclarePlayers; begin HowManyPlayers := 1; //Total Number of Players. CurrentPlayer := 0; //Starting Player. NumberOfPlayers(HowManyPlayers); Players[0].Name :='username'; //Username. Players[0].Pass :='password'; //Password. Players[0].Nick :='ern'; //Nickname. (4 Letters of your username) Players[0].Active := True; //Is the player active? Players[0].Pin := '1234'; //Leave blank if you dont have one. end;
Code:{.include LoginDetails.scar}
SCAR Code:program TheFile;
function ReadTheFile( PathToFile: String; I: Integer ): String;
var S: String;
F: Integer;
TheArray: Array of String;
begin
F := OpenFile( PathToFile, False );
ReadFileString( F, S, FileSize( F ) );
CloseFile( F );
TheArray := Explode( ';', S );
Result := TheArray[ I ];
end;
function WriteTheFile( PathToFile, NewString: String; I: Integer ): Boolean;
var S, TheString: String;
F, O: Integer;
TheArray: Array of String;
begin
TheString := '';
F := OpenFile( PathToFile, False );
ReadFileString( F, S, FileSize( F ) );
CloseFile( F );
TheArray := Explode( ';', S );
TheArray[ I ] := NewString;
for O := 0 to GetArrayLength( TheArray ) - 1 do
begin
if not ( O = 0 ) then begin
TheArray[ O ] := ';' + TheArray[ O ];
end;
TheString := TheString + TheArray[ O ];
end;
F := RewriteFile( PathToFile, False );
WriteFileString( F, TheString );
CloseFile( F );
Result := True;
end;
begin
Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
WriteTheFile( ScriptPath + 'test.txt', 'usernametest', 0 );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
WriteTheFile( ScriptPath + 'test.txt', 'passwordtest', 1 );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
WriteTheFile( ScriptPath + 'test.txt', 'pintest', 2 );
Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
end.
{OUTPUT:
Successfully compiled (25 ms)
username
password
pin
usernametest
passwordtest
pintest
Successfully executed
FILE:
username;password;pin
}
The function worked good but i still recommend to use ini files.
E: Added a write function.
Last edited by Frement; 02-01-2010 at 05:58 AM.
There used to be something meaningful here.
Thank you all for your help. Very informative.
I'm still confused on why you need this..?
There are currently 1 users browsing this thread. (0 members and 1 guests)