SRL Archive - SRL Suggestions

SRL Shortening


Dan Cardin

2009-06-19 21:24:17

I am not sure if anything I am doing makes a difference, but whatever.

FindCoins
  V: array [0..1] of TVariantArray;//i changed that 1 from a 2 since i couldnt find where a a [2] would be used.


function CheckArea(area: string): Boolean;
doesnt need the writeln at the end. Its checking to see if one is open, writing it is pointless.


AreaInfo
procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
colnumber, rownumber: Integer);
var a: array [0..4] of tintegerarray;
e: integer;
begin
a[0] := [560,212,36,42,4,7];
a[1] := [63,97,55,39,21,4];
a[2] := [35,91,44,44,10,5];
a[3] := [310,75,32,49,4,7];
a[4] := [24,75,32,49,4,7];
case LowerCase(area) of
'inv', 'inventory': e := 0;
'shop': e := 1;
'bank': e := 2;
'trade': e := 3;
'your trade': e := 4;
else writeln('AreaInfo');
end;
startx := a[e][0];
starty := a[e][1];
rowsize := a[e][2];
colsize := a[e][3];
colnumber := a[e][4];
rownumber := a[e][5];
end;
That is shortened quite bit.

EDIT: but this is better
procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
colnumber, rownumber: Integer);
var a: array [0..4] of tintegerarray;
s: TStringArray;
e, i: integer;
Opt : TIntegerArray;
begin
a[0] := [560,212,36,42,4,7];
a[1] := [63,97,55,39,21,4];
a[2] := [35,91,44,44,10,5];
a[3] := [310,75,32,49,4,7];
a[4] := [24,75,32,49,4,7];
Opt := [startx, starty, rowsize, colsize, colnumber, rownumber];
s := ['inv', 'inventory', 'shop', 'bank', 'trade', 'your trade'];
for I := 2 to High(S) Do
case LowerCase(area) of
s[I] : e := i - 1;
end;
writeln(e);
for I := 0 To High(Opt) Do
Opt[I] := a[e][I];
end;

Small things, but yah.

I also wonder if all the headings and whatnot are good for being in the code. I can see them being nicely documented somewhere, but having them all inside the code itself just makes the files larger and annoying to navigate through. I would say doing something similar to the php manual, with all nice examples and stuff inside, but that would probably be a large undertaking. Lacking that, I think just making sure there is documentation online of all of the functions would be enough to have and just delete everything out of the code itself.

So far ive only gone through amount.scar, but there will probably be other shortenings that can be done. I dont know what the devs do exactly, but going back through SRL functions, even if its not broken, to see what can be improved upon could prove useful if not already done.

Anyways, I was just perusing SRL and saw a few things i might be able to improve upon.

Quickmarch

2009-06-19 21:27:30

I've got one here too, i made it only one line:


function InvEmpty: Boolean;
begin
Result := InvCount = 0;
end;

Naike

2009-06-19 22:35:29

If I recall correctly,
Wizzup wants to keep the original Pascal.
And not the [0..25] stuff, so goes for a := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Naum

2009-06-20 00:06:51

My contribution (not sure if it works)

Function TradeScreen: Variant;
Begin
Result := (GetColor(90, 61) = 2070783)
If Result = 0 Then Result := 2;
End;

Edit, on your first proc :).


procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
colnumber, rownumber: Integer);
var a: array [0..4] of tintegerarray;
s: TStringArray;
e, i: integer;
begin
a[0] := [560,212,36,42,4,7];
a[1] := [63,97,55,39,21,4];
a[2] := [35,91,44,44,10,5];
a[3] := [310,75,32,49,4,7];
a[4] := [24,75,32,49,4,7];
s := ['inv', 'inventory', 'shop', 'bank', 'trade', 'your trade'];
For I := 0 to High(S) Do
case LowerCase(area) of
s[I] : e := StrToint(S[I]);
else writeln('AreaInfo');
end;
startx := a[e][0];
starty := a[e][1];
rowsize := a[e][2];
colsize := a[e][3];
colnumber := a[e][4];
rownumber := a[e][5];
end;

You should also store rownumber and those categorical variables to an Integer Array then use a loop to call them :)

Edit, just did that:

procedure AreaInfo(area: string; var startx, starty, rowsize, colsize,
colnumber, rownumber: Integer);
var a: array [0..4] of tintegerarray;
s: TStringArray;
e, i: integer;
Opt : TIntegerArray;
begin
a[0] := [560,212,36,42,4,7];
a[1] := [63,97,55,39,21,4];
a[2] := [35,91,44,44,10,5];
a[3] := [310,75,32,49,4,7];
a[4] := [24,75,32,49,4,7];
Opt := [startx, starty, rowsize, colsize, colnumber, rownumber];
s := ['inv', 'inventory', 'shop', 'bank', 'trade', 'your trade'];
For I := 0 to High(S) Do
case LowerCase(area) of
s[I] : e := StrToint(S[I]);
else writeln('AreaInfo');
end;
For I := 0 To High(Opt) Do
Opt[I] := a[e][I];
end;

ShowerThoughts

2009-06-20 00:11:37

People remember, shortened doesn't means better++ it just makes readable– ;).

Dan Cardin

2009-06-20 04:37:49

NaumanAkhlaQ - Your version calls inv and inventory different numbers by the way. and idk what that opt deal is supposed to do.

Hermen - shortened = better if it works better. And to me, shortened, even if more complicated things are happening, is less complicated since i can see everything. For example i could make a function like this

function meow(m,q: integer): integer;
var a,b,e,c,d, l: integer;
begin
a := 5;
b := 15
c := m;
d := q;
e := q+m;
l := a + b + c+ d+ e*2;
result := l;
end;
but that could easily be turned into one line. And still be better.

n1ke! - i have no idea what you mean.

Naum

2009-06-20 13:07:16

From: Dan Cardin
NaumanAkhlaQ - Your version calls inv and inventory different numbers by the way. and idk what that opt deal is supposed to do.

Hermen - shortened = better if it works better. And to me, shortened, even if more complicated things are happening, is less complicated since i can see everything. For example i could make a function like this

function meow(m,q: integer): integer;
var a,b,e,c,d, l: integer;
begin
a := 5;
b := 15
c := m;
d := q;
e := q+m;
l := a + b + c+ d+ e*2;
result := l;
end;
but that could easily be turned into one line. And still be better.

n1ke! - i have no idea what you mean.

First Question, your correct sorry :(. Also the 'opt' deal is to set the number looping through the array so 'inv' would be 0 and 'inventory' would be 1 (which is wrong atm) andso on (if I can fix it :))

ZephyrsFury

2009-06-20 13:50:34

From: NaumanAkhlaQ
My contribution (not sure if it works)

Function TradeScreen: Variant;
Begin
Result := (GetColor(90, 61) = 2070783)
If Result = 0 Then Result := 2;
End;

Edit, on your first proc :).



No that wouldn't work. And why a variant?


Description: Returns 1 or 2 for the respective tradescreens, 0 if neither is open.

Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.

Daniel

2009-06-20 15:04:22

From: Dan Cardin

n1ke! - i have no idea what you mean.


I think he means that Wizzup doesn't want to count the 0 in arrays.

Naum

2009-06-20 18:48:03

From: ZephyrsFury
No that wouldn't work. And why a variant?


Description: Returns 1 or 2 for the respective tradescreens, 0 if neither is open.

Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.


Uhh would'nt that return the GetColor of 0?

Dan Cardin

2009-06-20 19:57:05

Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.
I disagree. If you needed to change a value, then just change it, they're all in the same line. If you need to add more areas, then you just change the array size and add another line, where in your way, you need to add another case section and it would get bigger and more annoying.

For the most part, shortening it in the way that i did, is better imo.

Nava2

2009-06-21 07:35:55

From: Dan Cardin
I disagree. If you needed to change a value, then just change it, they're all in the same line. If you need to add more areas, then you just change the array size and add another line, where in your way, you need to add another case section and it would get bigger and more annoying.

For the most part, shortening it in the way that i did, is better imo.


I agree, it does need to be commented though.

Claymore

2009-06-21 09:39:41

get rid of 0 in arrays pl0x….hate it because it ??? me.

senrath

2009-06-21 09:45:48

From: Deathscytex
get rid of 0 in arrays pl0x….hate it because it ??? me.


Really? Most of the languages I know use 0 indexed arrays.

ShowerThoughts

2009-06-21 13:39:50

From: senrath
Really? Most of the languages I know use 0 indexed arrays.


I think all but really a few don't.

Dan Cardin

2009-06-21 17:17:37

From: Nava2
I agree, it does need to be commented though.
Like i said. As long as there was good documentation in a separate help file, or online (or both), then it's not needed inside the code itself as it just makes the files bigger, longer, and more confusing. At first it would be fine to just transport everything to being separate, but I think it would be much better to have a PHP like manual that is much more extensive eventually (like what Freddy started doing with SCAR).

Wizzup?

2009-06-21 18:18:48

From: ZephyrsFury
No that wouldn't work. And why a variant?


Description: Returns 1 or 2 for the respective tradescreens, 0 if neither is open.

Anyway tbh guys, the current AreaInfo is a lot easier to look at and understand and fix if its broken by an update.


I agree with Zeph.