Cheesehunk
2007-10-09 19:32:25
I haven't been active with SCAR for a while now, as many of you know.. However, I was making a small script for a Guitar hero Tournament to pick 5 songs for the competition. Then, it would save them to a file (Where I am..) and read them later for future competitions to see if they have already been used.
I keep getting file access errors, and haven't messed with SCAR in a while, so I'm not 100%. I know you guys will gladly help me, being why I came here.
Anyways, take a look:
Thanks,
Cheesehunk.:)
I keep getting file access errors, and haven't messed with SCAR in a while, so I'm not 100%. I know you guys will gladly help me, being why I came here.
Anyways, take a look:
program SongPicker;
var Songs: array [0..63] of String;
UsedSongs: array of String;
TheSongs: array of Integer;
i, TheFile: Integer;
const
SaveFile = True;
ThePath = 'C:\Documents and Settings\Dave\Desktop\Un-used Desktop\Songs.txt';
Procedure SetSongs;
begin
Songs[0] := 'Yes We Can';
Songs[1] := 'Shout at the Devil';
Songs[2] := 'Mother';
Songs[3] := 'Surrender';
Songs[4] := 'Woman';
Songs[5] := 'Tonight I''m Gonna Rock You Tonight';
Songs[6] := 'Strutter';
Songs[7] := 'Heart-Shaped Box';
Songs[8] := 'Message in a bottle';
Songs[9] := 'You Really Got Me';
Songs[10] := 'Carry on Wayward Son';
Songs[11] := 'Monkey Wrench';
Songs[12] := 'Them Bones';
Songs[13] := 'Search and Destroy';
Songs[14] := 'Tattoed Love Boys';
Songs[15] := 'War Pigs';
Songs[16] := 'Cherry Pie';
Songs[17] := 'Who Was in my Room Last Night?';
Songs[18] := 'Girlfriend';
Songs[19] := 'Can''t You Hear Me Knockin';
Songs[20] := 'Sweet Child o'' Mine';
Songs[21] := 'Killing in the Name';
Songs[22] := 'John the Fisherman';
Songs[23] := 'Freya';
Songs[24] := 'Bad Reputation';
Songs[25] := 'Last Child';
Songs[26] := 'Crazy on You';
Songs[27] := 'Trippin'' on a Hole in a paper Heart';
Songs[28] := 'Rock This Town';
Songs[29] := 'Jessica';
Songs[30] := 'Stop';
Songs[31] := 'Madhouse';
Songs[32] := 'Carry Me Home';
Songs[33] := 'Laid to Rest';
Songs[34] := 'Physchobilly Freakout';
Songs[35] := 'YYZ';
Songs[36] := 'Beast and the Harlot';
Songs[37] := 'Institutionalized';
Songs[38] := 'Misirlou';
Songs[39] := 'Hangar 18';
Songs[40] := 'Free Bird';
Songs[41] := 'Raw Dog';
Songs[42] := 'Arterial Black';
Songs[43] := 'Collide';
Songs[44] := 'Elephant Bones';
Songs[45] := 'Fall of Pangea';
Songs[46] := 'FTK';
Songs[47] := 'Gemini';
Songs[48] := 'Laughtrack';
Songs[49] := 'Less Talk More Rokk';
Songs[50] := 'Mr. Fix It';
Songs[51] := 'The New Black';
Songs[52] := 'One for the Road';
Songs[53] := 'Parasite';
Songs[54] := 'Push Push (Lady Lightning)';
Songs[55] := 'Radium Eyes';
Songs[56] := 'Red Lottery';
Songs[57] := 'Six';
Songs[58] := 'Soy Bomb';
Songs[59] := 'The Light That Blinds';
Songs[60] := 'Thunderhorse';
Songs[61] := 'Trogdor';
Songs[62] := 'X-Stream';
Songs[63] := 'Jordan';
end;
procedure PickSongs(Songz: array of Integer);
var i, TheSong: Integer;
begin
for i := 0 to 4 do
begin
TheSong := Random(63) + 1;
if (TheSong = Songz[0])
or (TheSong = Songz[1])
or (TheSong = Songz[2])
or (TheSong = Songz[3])
or (TheSong = Songz[4]) then
i := i - 1
else
Songz[i] := TheSong;
end;
end;
procedure SetupFile; //credits to RsN
var aFile: Integer;
cString: String;
begin
if not FileExists(ThePath) then
TheFile := RewriteFile(ThePath, False);
aFile:= OpenFile(ThePath, False);
if (aFile < 0) then
Exit;
ReadFileString(aFile, cString, FileSize(aFile));
CloseFile(aFile);
TheFile := RewriteFile(ThePath, False);
WriteFileString(TheFile, cString);
end;
Function FindAllOcc(LookFor, TheString : String) : Integer; //Ron
Var
a : Integer;
b : LongInt;
FunctStr : String;
Begin
FunctStr := TheString;
Repeat
b := Pos(LookFor, FunctStr);
If(Not(b = 0))Then
Begin
a := a + 1;
End;
FunctStr := Replace(FunctStr, LookFor, '');
Until(b = 0)
Result := a;
End;
function Explode(Separator, TheString : String) : Array of String; //Ron
var
ArrayName : Array of String;
FunctStr, c : String;
a, i : Integer;
begin
FunctStr := TheString;
a := FindAllOcc(Separator, FunctStr);
SetArrayLength(ArrayName, a+1);
for i := 0 to a do
begin
if(i = a)then
begin
ArrayName[i] := FunctStr;
end else
begin
c := Copy(FunctStr, 1, Pos(Separator, FunctStr)-1);
ArrayName[i] := c;
FunctStr := Replace(FunctStr, c+Separator, '');
end;
end;
Result := ArrayName;
end;
procedure LoadUsedSongs;
var bFile: Integer;
aString: String;
begin
bFile := OpenFile(ThePath, False);
if (bFile < 0) then
Exit;
ReadFileString(bFile, aString, FileSize(bFile));
CloseFile(bFile);
UsedSongs := Explode('.', aString);
WriteLn(IntToStr(GetArrayLength(UsedSongs)));
for i := 0 to GetArrayLength(UsedSongs) - 1 do
WriteLn(UsedSongs[i]);
end;
begin
SetSongs;
if SaveFile then SetupFile;
SetArrayLength(TheSongs, 5);
if SaveFile then LoadUsedSongs;
PickSongs(TheSongs);
for i := 0 to 4 do
begin
WriteLn('Song ' + IntToStr(i + 1) + ': ' + Songs[TheSongs[i]]);
if SaveFile then WriteFileString(TheFile, '.' + IntToStr(TheSongs[i]));
end;
end.Thanks,
Cheesehunk.:)