SRL Archive - Jr. Member General Help and Discussion

Standards.


Zeta Matt

2013-09-17 18:49:16

There is way too many statements here, lots of ":integer;". How to fix my standards on this:
Function FindBitMapRotatedIn(bitmap: integer; var x: integer; var y: Integer; xs, ys, xe, ye: integer; tolerance: integer; AngleRotationSpeed: integer): Boolean; 
I tried picking out some "integer", but it wouldn't compile, saying:
[Error] C:\Simba\Scripts\DivinationUpgradedScript.simba(94:38): Identifier expected at line 93

[EDIT]According to this standards tutorial: http://villavu.com/forum/showthread.php?t=60288 (Copy/paste this on cntrl+F : "Where possible, procedure and function formal")
How can I combine every integer parameter in one statement? It seems the variables X and Y have to be in a separated statement, or something like that…

Kevin

2013-09-17 18:59:14

Function FindBitMapRotatedIn(bitmap: integer; var x: integer; var y: Integer; xs, ys, xe, ye: integer; tolerance: integer; AngleRotationSpeed: integer): Boolean;
procedure CallsFindBitMapRotatedIn(bmp, tol: integer);//bmp represents the value the bitmap is stored to, tol represents the tolerance for coloring/deformation of the bitmap
var
x, y: integer;//x and y represent the location the bitmap is found at.
begin
if(FindBitMapRotatedIn(bmp, x, y, MMX1, MMY1, MMX2, MMY2, tol, 3))then//MMX1-MMY2 represent checking the main screen. x and y HAVE to be variable names, you CANNOT pass constants (3, 4 for example) to it, because it is going to cahnge the value in the return so it can tell you where it found the bitmap. everything else can technically be a constant integer.
begin
//you found it, yay! It exists at Point(x, y)
end;
end;

Hope that description helps :)

Zeta Matt

2013-09-17 19:28:35

Yeah, I understood what you did there… no constants at variables and stuff. But what I really wanted is to write that function according to this standars tutorial: http://villavu.com/forum/showthread.php?t=60288 (Copy/paste this on cntrl+F : "Where possible, procedure and function formal")
How can I combine every integer parameter in one statement? It seems the variables X and Y have to be in a separated statement, or something like that…
I might have explained wrong, sorry :D I eddited the thread

Ian

2013-09-17 19:44:11

From: archermaths
Yeah, I understood what you did there… no constants at variables and stuff. But what I really wanted is to write that function according to this standars tutorial: http://villavu.com/forum/showthread.php?t=60288 (Copy/paste this on cntrl+F : "Where possible, procedure and function formal")
How can I combine every integer parameter in one statement? It seems the variables X and Y have to be in a separated statement, or something like that…


I'm fairly sure what it means by that is you should use

var
X, Y: Integer;
instead of

var
X: Integer;
Y: Integer;

Also to use

Function FindBitMapRotatedInA(bitmap, xs, ys, xe, ye, tolerance, AngleRotationSpeed: Integer; var x: Integer; var y:Integer): Boolean; //I know the last two are integers as well but they're variables not constants so maybe they need to be done like this.
instead of

Function FindBitMapRotatedIn(bitmap: integer; var x: integer; var y: Integer; xs, ys, xe, ye: integer; tolerance: integer; AngleRotationSpeed: integer): Boolean;

Also I tend to follow
Routine names shall always begin with a capital letter and be PascalCase for readability.

for variables as well, just for readability.

I also think acronyms like DTM should always be capped, but I don't know the official opinion on this.

Example:


procedure FreeTheDTMs;
begin
FreeDTM(TinOreDTM);
FreeDTM(CopperOreDTM);
FreeDTM(IronOreDTM);
FreeDTM(SilverOreDTM);
FreeDTM(GoldOreDTM);
FreeDTM(MithrilOreDTM);
FreeDTM(AdamantiteOreDTM);
FreeDTM(RuniteOreDTM);
FreeDTM(CoalDTM);
end;

vs


procedure FreeTheDTMs;
begin
FreeDTM(tinoredtm);
FreeDTM(copperoredtm);
FreeDTM(ironoredtm);
FreeDTM(silveroredtm);
FreeDTM(goldoredtm);
FreeDTM(mithriloredtm);
FreeDTM(adamantoredtm);
FreeDTM(runiteoredtm);
FreeDTM(coaldtm);
end;

Both work the same but I find that the first one is much more readable. :)

Zeta Matt

2013-09-17 20:34:40

Oh thankssssssssssssssss BMW! It's about that "Function FindBitMapRotatedInA(bitmap, xs, ys, xe, ye, tolerance, AngleRotationSpeed: Integer; var x: Integer; var y:Integer): Boolean;" I wanted, and it's working perfectly :) Tough, it feels too much different from how every DTM/BitMap/Color finder function works (tolerance last) >.< It feels strange, but I might get used to it =D ty again!

Ian

2013-09-17 20:42:43

From: archermaths
Oh thankssssssssssssssss BMW! It's about that "Function FindBitMapRotatedInA(bitmap, xs, ys, xe, ye, tolerance, AngleRotationSpeed: Integer; var x: Integer; var y:Integer): Boolean;" I wanted, and it's working perfectly :) Tough, it feels too much different from how every DTM/BitMap/Color finder function works (tolerance last) >.< It feels strange, but I might get used to it =D ty again!


I think you can put them wherever you want but group them together. (I'd probably put the two var ones first and then order the rest however I wanted)

Like

function FindBitMapRotatedIn(var x: Integer; var y:Integer; bitmap, xs, ys, xe, ye, tolerance, AngleRotationSpeed: Integer): Boolean;

riwu

2013-09-18 07:06:12

If you use Lape, you can easily change the parameter order of a function to your own liking through overloading (and even add default arguments to further allow yourself to be lazy :p)
Eg.

procedure FindColorTolerance(var x, y: Integer; color, tol: Integer; box: TBox = MSBOX); overload;
begin
FindColorTolerance(x, y, color, box.x1, box.y1, box.x2, box.y2, tol);
end;

Zeta Matt

2013-09-18 14:32:37

Lol, seems cool :D Tough, even letting us be lazy for some moments, it screws up a bit with readability… that's something I could use for private scripts =D

riwu

2013-09-19 07:30:31

From: archermaths
Lol, seems cool :D Tough, even letting us be lazy for some moments, it screws up a bit with readability… that's something I could use for private scripts =D

Default argument is a feature of most high level languages and does not screw up readability at all :)

Zeta Matt

2013-09-20 23:11:39

From: riwu
Default argument is a feature of most high level languages and does not screw up readability at all :)

Yes! The default arguments wouldn't screw readability, it's pretty good :) I was working on a artisan's workshop helper and, since every bitmap I wanted was on inventory, I just created a FindBmpTolInv function for it… saved a lot of work! Anyway… I wanted to say that changing the order of the parameters (by overloading, which I don't know how to do) would be a bit strange for some script available for people… it's like suddenly seeing FindColorTolerance(0, 0, 1000, 1000, 228945, x, y, 5); Correct me if I misunderstood what overloading is :D

samerdl

2013-09-21 06:38:12

Simba > Parser > format script :)

i never bother to do that, if the script works then it works :o