SRL Archive - SRL Archives

TreeNames *Meh*


Special Ed

2007-03-12 17:12:28

Takes a name and splits it for you into three portions, so if you put in something like "Willow" you'd get "Wil" "ilo" llo" and if you put something like "Tree" in you get "Tre" "ree "Tre" you get the first name twice so you don't get a blank value, anyways its doesn't lag and is really quite helpful for an any tree power chopper or something so in setup you don't have to put in the multiple names.

function TreeNames(TreeName:string):string;
var x:integer;
begin
if(Length(TreeName) >= 3)then
begin
x:= 1
TreeName1:= (TreeName[1]+TreeName[2]+TreeName[3]);
if(Length(TreeName) >= 4)then
begin
x:= 2
TreeName2:= (TreeName[2]+TreeName[3]+TreeName[4]);
if(Length(TreeName) >= 5)then
begin
x:= 3
TreeName3:= (TreeName[3]+TreeName[4]+TreeName[5]);
end;
end;
end;
if(x = 1)then
begin
result:= (TreeName1);
TreeName2:= TreeName1
result:= (TreeName2);
TreeName3:= TreeName1
result:= (TreeName3);
end;
if(x = 2)then
begin
result:= (TreeName1);
result:= (TreeName2);
TreeName3:= TreeName1
result:= (TreeName3);
end;
if(x = 3)then
begin
result:= (TreeName1);
result:= (TreeName2);
result:= (TreeName3);
end;
end;

Ron

2007-03-12 17:26:15

This may be useful. Nice work. :)

Instead of using StrGet there is a much easier way of getting 1 character in a string.

Here is an example.


program ForgetStrGetAndUseThisTechniqueMuahahahaByRon;

var
Moo : String;

begin
ClearDebug;
Moo := 'Hello, how are you today?';
WriteLn('1st Char: ' + Moo[1]);
WriteLn('10th Char: ' + Moo[10]);
WriteLn('Last Char: ' + Moo[Length(Moo)]);
end.

and for the if(x = 1) … (x = 2) … etc. You could shorten that a lot. I don't know why you set Result equal to several different things in each if statement. Please look it over. :)

~Ron :D

bullzeye95

2007-03-12 17:29:57

Oh wow Ron, I had no idea you could do that! Thanks alot :)

Special Ed

2007-03-12 19:01:05

Thank for the tip in using the [1] and stuff that will make it shorter but for using multiple results it's because it has multiple results and it makes it so you can't get a result that is blank without it crashing.

And for yours it doesn't work if you do a character that doesn't fit in "Moo" like…

Writeln(Moo[15]);

Returns: [Runtime Error] : Out Of String Range in line _ in script

I don't really know a lot about functions but it just worked well the way I had it.

TOB

2007-03-13 11:31:42

EDIT: I just got on a computer with a USB drive and rewrote it, I'm pretty sure it will work every time now.

program CreatePartialNames;

var
AllNames: array of string;

function PartialNames(Name: string; MinStrLength, Outputs: Integer): array of string;
var Rand1, Rand2, NameLength, i: Integer;
begin
if(Outputs < 1) then
begin
SetArrayLength(Result, 1);
Result[0]:= Name;
Exit;
end else
begin
SetArrayLength(Result, Outputs + 1);
Result[0]:= Name;
NameLength:= Length(Name);
for i:= 1 to Outputs do
begin
Rand1:= Random(NameLength);
if((NameLength - MinStrLength) < Rand1) then
Rand1:= MinStrLength;
//Writeln('Rand1=' + IntToStr(Rand1));
Rand2:= MinStrLength + Random(NameLength - Rand1);
//Writeln('Rand2=' + IntToStr(Rand2));
Result[i]:= copy(Name, Rand1, Rand2)
end;
end;
end;

function strArrayToStr(strArray: array of string): string;
var
i, arrayLength: Integer;
begin
arrayLength := GetArrayLength(strArray);
repeat
Result := Result + (strArray[i]);
if (not(i = (arrayLength - 1))) then
Result := Result + ''' ''';
i := i + 1;
until (i = arrayLength)
Result:= '''' + Result + '''';
end;

begin
AllNames:= PartialNames('Willow', 3, 5);
Writeln(strArrayToStr(AllNames));
end.

Special Ed

2007-03-13 16:25:51

Hey great Idea but one problem… you get the same names a lot, and you cant really use it in something like "FindObjMultiText" where you use multiple names because your function doesn't return multiple values.

But its a good idea with using arraylength because then you can make it work with a string of any length.

* If you don't mind I'm going to try modding this some more to see if I can make it work *

TOB

2007-03-13 17:06:19

Sure go ahead, that's why I made it output a string array instead of a one or two strings, this way you can compare them to see if they are the same. When I wrote it I had meant to place a check to see if any names came up more than once and if they did to shorten the array by one and remove that, but I forgot xD

Ron

2007-03-13 17:25:12

From: Special Ed
Thank for the tip in using the [1] and stuff that will make it shorter but for using multiple results it's because it has multiple results and it makes it so you can't get a result that is blank without it crashing.

And for yours it doesn't work if you do a character that doesn't fit in "Moo" like…

Writeln(Moo[15]);

Returns: [Runtime Error] : Out Of String Range in line _ in script

I don't really know a lot about functions but it just worked well the way I had it.


lol no kidding. That happens when there isn't a character at the 15th position because the string was too small.

And all that code above were just examples. I was hoping you would see that you could use it in a loop such as…


program MoreExamplesByRon;

procedure SendKeysToDebug(Text : String);
var
i : Integer;
begin
for i := 1 to Length(Text) do
begin
WriteLn(Text[i]);
Wait(300);
end;
end;

begin
ClearDebug;
SendKeysToDebug('Wow look at this. I don''t get any runtime errors. Woo Hoo!');
end.

~Ron