SRL Archive - SRL Suggestions

Some functions


Frement

2010-05-08 11:16:43

Some functions someone on #SRL thought are worth posting :P
{*******************************************************************************
function TVAtoTSA(arr: TVariantArray): TStringArray;
Description: Converts TVariantArray to TStringArray.
*******************************************************************************}
function TVAtoTSA(arr: TVariantArray): TStringArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
try begin
Result[I] := arr[I];
end except
Inc(F);
end;
end;
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

{*******************************************************************************
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
Description: Converts TVariantArray to TIntegerArray.
*******************************************************************************}
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
try begin
Result[I] := arr[I];
end except
Inc(F);
end;
end;
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

{*******************************************************************************
function CombineTSA(arr1, arr2: TStringArray): TStringArray;
Description: Combines two TStringArrays and returns the combined TStringArray.
*******************************************************************************}
function CombineTSA(arr1, arr2: TStringArray): TStringArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1)+Length(arr2));
for I := 0 to High(arr2) do begin
arr1[N+I+1] := arr2[I];
end;
Result := arr1;
end;

{*******************************************************************************
function CombineTIA(arr1, arr2: TIntegerArray): TIntegerArray;
Description: Combines two TIntegerArrays and returns the combined TIntegerArray.
*******************************************************************************}
function CombineTIA(arr1, arr2: TIntegerArray): TIntegerArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1)+Length(arr2));
for I := 0 to High(arr2) do begin
arr1[N+I+1] := arr2[I];
end;
Result := arr1;
end;

{*******************************************************************************
function CombineTVA(arr1, arr2: TVariantArray): TVariantArray;
Description: Combines two TVariantArrays and returns the combined TVariantArray.
*******************************************************************************}
function CombineTVA(arr1, arr2: TVariantArray): TVariantArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1)+Length(arr2));
for I := 0 to High(arr2) do begin
arr1[N+I+1] := arr2[I];
end;
Result := arr1;
end;

Coh3n

2010-05-10 14:56:12

For the conversion functions, you'll need try..except blocks in case the variant array index isn't actually the type you want to convert to.

Frement

2010-05-10 15:09:49

From: Coh3n
For the conversion functions, you'll need try..except blocks in case the variant array index isn't actually the type you want to convert to.


Actually it can convert them just fine (had to check again to be sure :)):
program New;
{.Include SRL/SRL.scar}

var tvaa: TVariantArray;
tvii: TIntegerArray;
tsaa: TStringArray;
I: Integer;

{*******************************************************************************
function TVAtoTSA(arr: TVariantArray): TStringArray;
Description: Converts TVariantArray to TStringArray.
*******************************************************************************}
function TVAtoTSA(arr: TVariantArray): TStringArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
try begin
Result[I] := arr[I];
end except
Inc(F);
end;
end;
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

{*******************************************************************************
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
Description: Converts TVariantArray to TIntegerArray.
*******************************************************************************}
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
try begin
Result[I] := arr[I];
end except
Inc(F);
end;
end;
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

begin
SetupSRL;

SetArrayLength(tvaa, 2);
SetArrayLength(tvii, 2);

tvaa[0] := '1';
tvaa[1] := 2;

tvii := TVAtoTIA(tvaa);

for I := 0 to High(tvii) do begin
Writeln(inttostr(tvii[I]));
end;

tsaa := TVAtoTSA(tvaa);

for I := 0 to High(tsaa) do begin
Writeln(tsaa[I]);
end;
end.
Output:
[PHP]Successfully compiled (1548 ms)
SRL Compiled in 0 msec
1
2
1
2
Successfully executed[/PHP]

Sir R. M8gic1an

2010-05-10 15:23:57

Aren't most of these in wizzy pluggin already..?

~RM

mastaraymond

2010-05-10 15:25:04

From: Frement
Actually it can convert them just fine (had to check again to be sure :)):
program New;
{.Include SRL/SRL.scar}

var tvaa: TVariantArray;
tvii: TIntegerArray;
tsaa: TStringArray;
I: Integer;

{*******************************************************************************
function TVAtoTSA(arr: TVariantArray): TStringArray;
Description: Converts TVariantArray to TStringArray.
*******************************************************************************}
function TVAtoTSA(arr: TVariantArray): TStringArray;
var I: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
Result[I] := arr[I];
end;
end;

{*******************************************************************************
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
Description: Converts TVariantArray to TIntegerArray.
*******************************************************************************}
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
var I: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
Result[I] := arr[I];
end;
end;

begin
SetupSRL;

SetArrayLength(tvaa, 2);
SetArrayLength(tvii, 2);

tvaa[0] := '1';
tvaa[1] := 2;

tvii := TVAtoTIA(tvaa);

for I := 0 to High(tvii) do begin
Writeln(inttostr(tvii[I]));
end;

tsaa := TVAtoTSA(tvaa);

for I := 0 to High(tsaa) do begin
Writeln(tsaa[I]);
end;
end.
Output:
[PHP]Successfully compiled (1548 ms)
SRL Compiled in 0 msec
1
2
1
2
Successfully executed[/PHP]


program New;
{.Include SRL/SRL.scar}

var tvaa: TVariantArray;
tvii: TIntegerArray;
tsaa: TStringArray;
I: Integer;

{*******************************************************************************
function TVAtoTSA(arr: TVariantArray): TStringArray;
Description: Converts TVariantArray to TStringArray.
*******************************************************************************}
function TVAtoTSA(arr: TVariantArray): TStringArray;
var I: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
Result[I] := arr[I];
end;
end;

{*******************************************************************************
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
Description: Converts TVariantArray to TIntegerArray.
*******************************************************************************}
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
var I: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do begin
Result[I] := arr[I];
end;
end;

begin
SetupSRL;

SetArrayLength(tvaa, 2);
SetArrayLength(tvii, 2);

tvaa[0] := 'Jemoeder';
tvaa[1] := 2;

tvii := TVAtoTIA(tvaa);

for I := 0 to High(tvii) do begin
Writeln(inttostr(tvii[I]));
end;

tsaa := TVAtoTSA(tvaa);

for I := 0 to High(tsaa) do begin
Writeln(tsaa[I]);
end;
end.
Try ^

Frement

2010-05-10 15:37:13

Ok, well added try..except to first post.

i luffs yeww

2010-05-10 17:12:21


{*******************************************************************************
function TVAtoTSA(arr: TVariantArray): TStringArray;
Description: Converts TVariantArray to TStringArray.
*******************************************************************************}
function TVAtoTSA(arr: TVariantArray): TStringArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to[/B][/COLOR] High(arr) do
try
Result[I] := arr[I];
except
Inc(F);
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

{*******************************************************************************
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
Description: Converts TVariantArray to TIntegerArray.
*******************************************************************************}
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do
try
Result[I] := arr[I];
except
Inc(F);
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

{*******************************************************************************
function CombineTSA(arr1, arr2: TStringArray): TStringArray;
Description: Combines two TStringArrays and returns the combined TStringArray.
*******************************************************************************}
function CombineTSA(arr1, arr2: TStringArray): TStringArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1) + Length(arr2));
for I := 0 to High(arr2) do
arr1[N + I + 1] := arr2[I];
Result := arr1;
end;

{*******************************************************************************
function CombineTIA(arr1, arr2: TIntegerArray): TIntegerArray;
Description: Combines two TIntegerArrays and returns the combined TIntegerArray.
*******************************************************************************}
function CombineTIA(arr1, arr2: TIntegerArray): TIntegerArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1) + Length(arr2));
for I := 0 to High(arr2) do
arr1[N + I + 1] := arr2[I];
Result := arr1;
end;

{*******************************************************************************
function CombineTVA(arr1, arr2: TVariantArray): TVariantArray;
Description: Combines two TVariantArrays and returns the combined TVariantArray.
*******************************************************************************}
function CombineTVA(arr1, arr2: TVariantArray): TVariantArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1) + Length(arr2));
for I := 0 to High(arr2) do
arr1[N + I + 1] := arr2[I];
Result := arr1;
end;

Your standards always bug me..

Something's wrong with school computers.

And really.. I'm just jealous that you're so hawt. :<

Dude what. For some reason it keeps changing how the text is. Screw school. D:

Frement

2010-05-10 17:13:42

From: i luffs yeww
Code:
[LEFT]{*******************************************************************************
function TVAtoTSA(arr: TVariantArray): TStringArray;
Description: Converts TVariantArray to TStringArray.
*******************************************************************************}

function TVAtoTSA(arr: TVariantArray): TStringArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do
try
Result := arr;
except
Inc(F);
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

{*******************************************************************************
function TVAtoTIA(arr: TVariantArray): TIntegerArray;
Description: Converts TVariantArray to TIntegerArray.
*******************************************************************************}

function TVAtoTIA(arr: TVariantArray): TIntegerArray;
var I, F: Integer;
begin
SetArrayLength(Result, Length(arr));
for I := 0 to High(arr) do
try
Result := arr;
except
Inc(F);
if (F > 0) then
Writeln('Failed to convert '+IntToStr(F)+' values.');
end;

{*******************************************************************************
function CombineTSA(arr1, arr2: TStringArray): TStringArray;
Description: Combines two TStringArrays and returns the combined TStringArray.
*******************************************************************************}

function CombineTSA(arr1, arr2: TStringArray): TStringArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1) + Length(arr2));
for I := 0 to High(arr2) do
arr1[N + I + 1] := arr2;
Result := arr1;
end;

{*******************************************************************************
function CombineTIA(arr1, arr2: TIntegerArray): TIntegerArray;
Description: Combines two TIntegerArrays and returns the combined TIntegerArray.
*******************************************************************************}

function CombineTIA(arr1, arr2: TIntegerArray): TIntegerArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1) + Length(arr2));
for I := 0 to High(arr2) do
arr1[N + I + 1] := arr2;
Result := arr1;
end;

{*******************************************************************************
function CombineTVA(arr1, arr2: TVariantArray): TVariantArray;
Description: Combines two TVariantArrays and returns the combined TVariantArray.
*******************************************************************************}

function CombineTVA(arr1, arr2: TVariantArray): TVariantArray;
var I, N: Integer;
begin
N := High(arr1);
SetArrayLength(arr1, Length(arr1) + Length(arr2));
for I := 0 to High(arr2) do
arr1[N + I + 1] := arr2;
Result := arr1;
end;

[/LEFT]
[/LEFT]


Your standards always bug me.. ;)


Whats wrong with them?

Coh3n

2010-05-10 18:46:32

Probably doesn't like the way you use the begin..end nests.

Wanted

2010-05-10 20:10:01

These wouldn't be useful unless they are in a plugin, can't really think of any uses for them tbh.

Frement

2010-05-11 06:32:14

From: IceFire908
These wouldn't be useful unless they are in a plugin, can't really think of any uses for them tbh.


Well, someone needed CombineTSA for something, thats the reason i made them at all.

And why not put inside WizzyPlugin? As it already has CombineTPA?

mastaraymond

2010-05-11 07:59:04

From: Frement
Well, someone needed CombineTSA for something, thats the reason i made them at all.

And why not put inside WizzyPlugin? As it already has CombineTPA?

Well basically because now one has ever needed this function (or it was already put in WizzyPlugin) and therefore it is probably an unneeded function..

ss23

2010-05-11 08:49:58

C'mon guys, the reason these were MADE was because they were needed. If we think back to a long time ago, I once made a function that I believed to be amazingly useful, but wasn't in SRL. It was PlayersActive, a simple function to return the number of players active. Before this, every script needed to write a function (or the full code) to find out if there were any players active. All I'm saying is that just because something isn't in SRL already, doesn't mean it's not needed, especially in this case where the functions were made specifically for someones need on IRC.
If you're going to talk about not needed functions, compare the ones Frement posted to some thing like AllPlayersInactive, which is the same as PlayersActive < 1. (I'm not picking on this function, just comparing how useful something like what Frement is to what's already in SRL)

Also, I would like to point out that I HATE THESE FUCTIONS, F**K OFF FREMENT.

Rich

2010-05-11 10:35:18

From: ss23
Also, I would like to point out that I HATE THESE FUCTIONS, F**K OFF FREMENT.
Lol?

Sir R. M8gic1an

2010-05-11 11:29:28

From: ss23

If you're going to talk about not needed functions, compare the ones Frement posted to some thing like AllPlayersInactive, which is the same as PlayersActive < 1. (I'm not picking on this function, just comparing how useful something like what Frement is to what's already in SRL)


AllPlayersInactive is useless when PlayersActive has already been added. People just use it cus they're lazy and the function is in the include.

~RM