SRL Archive - SRL Archives

Boxes in Globals.scar


Sir R. M8gic1an

2010-06-11 08:44:05


function MSBox: TBox;
begin
with Result do
begin
x1 := MSX1;
y1 := MSY1;
x2 := MSX2;
y2 := MSY2;
end;
end;

function MMBox: TBox;
begin
with Result do
begin
x1 := MMX1;
y1 := MMY1;
x2 := MMX2;
y2 := MMY2;
end;
end;

function MIBox: TBox;
begin
with Result do
begin
x1 := MIX1;
y1 := MIY1;
x2 := MIX2;
y2 := MIY2;
end;
end;

function MCBox: TBox;
begin
with Result do
begin
x1 := MCX1;
y1 := MCY1;
x2 := MCX2;
y2 := MCY2;
end;
end;

Very often I would rather pass a TBox to my functions than 4 coords, as I find it helps with readability and scripting speed. Which is why I suggest that these be added to globals.scar

~RM

Nava2

2010-06-11 08:49:11

Why not use IntToBox

Sir R. M8gic1an

2010-06-11 08:55:23

From: Nava2
Why not use IntToBox


Same shit?

Actually, using the type is faster.

program new;

function MSBox: TBox;
begin
with Result do
begin
x1 := 1;
y1 := 2;
x2 := 3;
y2 := 4;
end;
end;

function MSBox2: TBox;
begin
Result := IntToBox(1, 2, 3, 4);
end;

var i, t: integer;
begin
t := GetSystemTime;
for i:= 0 to 10000 do
MSBox;
writeln(GetSystemTime - t);

t := GetSystemTime;
for i:= 0 to 10000 do
MSBox2;
writeln(GetSystemTime - t);
end.


Compiled succesfully in 62 ms.
93
140
Successfully executed.


I also find it more readable, using the type.

~RM

Narcle

2010-06-11 08:55:39

From: Nava2
Why not use IntToBox


Stop trying to make common sense.


Function MSBox: TBox;
begin
Result := IntToBox(MSX1, MSY1, MSX2, MSY2);
end;
wat

Edit: @RM
Like your going to notice 0.0032ms…

nielsie95

2010-06-11 08:56:09

Why not use vars if you want speed?

Sir R. M8gic1an

2010-06-11 08:57:41

From: nielsie95
Why not use vars if you want speed?


How so?

From: Narcle

Edit: @RM
Like your going to notice 0.0032ms…


Like your going to care what it looks like. Might as well make it faster.
Still find it more readable as a type.

edit:
Nielsie, did you mean:

function GetMSBox: TBox;
begin
with Result do
begin
x1 := MSX1;
y1 := MSY1;
x2 := MSX2;
y2 := MSY2;
end;
end;

function GetMMBox: TBox;
begin
with Result do
begin
x1 := MMX1;
y1 := MMY1;
x2 := MMX2;
y2 := MMY2;
end;
end;

function GetMIBox: TBox;
begin
with Result do
begin
x1 := MIX1;
y1 := MIY1;
x2 := MIX2;
y2 := MIY2;
end;
end;

function GetMCBox: TBox;
begin
with Result do
begin
x1 := MCX1;
y1 := MCY1;
x2 := MCX2;
y2 := MCY2;
end;
end;

var
MSBox,
MMBox,
MIBox,
MCBox: TBox;

Procedure SetupBoxes;
begin
MSBox := GetMSBox;
MMBox := GetMMBox;
MIBox := GetMIBox;
MCBox := GetMCBox;
end;

~RM

nielsie95

2010-06-11 09:02:10

var MSBox: TBox;

is a lot faster than calling a function. The downside is that it needs initializing.

Sir R. M8gic1an

2010-06-11 09:03:11

From: nielsie95
var MSBox: TBox;

is a lot faster than calling a function. The downside is that it needs initializing.


yeah, I figured that's what you meant.
I guess it could always be initialized in SetupSRL ?

~RM

Narcle

2010-06-11 09:04:42

Var MSBox: TBox;

MSBox := IntToBox(MSX1, MSY1, MSX2, MSY2);

Idk looks nicer imo… and would be faster.

edit:
This kinda ties into my post for SRL 5

Sir R. M8gic1an

2010-06-11 09:20:37


{ MainScreen, Minimap, Inventory, Chat, Bank boxes as TBox }
var
MSBox, MMBox, MIBox, MCBox, MBBox: TBox;

{These next functions get the Boxes setup as consts into TBoxes}
function GetMSBox: TBox;
begin
Result := IntToBox(MSX1, MSY1, MSX2, MSY2);
end;

function GetMMBox: TBox;
begin
Result := IntToBox(MMX1, MMY1, MMX2, MMY2);
end;

function GetMIBox: TBox;
begin
Result := IntToBox(MIX1, MIY1, MIX2, MIY2);
end;

function GetMCBox: TBox;
begin
Result := IntToBox(MCX1, MCY1, MCX2, MCY2);
end;

function GetMBBox: TBox;
begin
Result := IntToBox(MBX1, MBY1, MBX2, MBY2);
end;

Procedure SetupBoxes;
begin
MSBox := GetMSBox;
MMBox := GetMMBox;
MIBox := GetMIBox;
MCBox := GetMCBox;
MBBox := GetMBBox;
end;

commited. Post later. edited srl.scar accordingly.

~RM

EvilChicken!

2010-06-11 15:41:36

Now to make all color searching functions accept TBoxes as params..

MylesMadness

2010-06-11 15:50:51

That doesn't make any sence, why not make it:

{ MainScreen, Minimap, Inventory, Chat, Bank boxes as TBox }
var
MSBox, MMBox, MIBox, MCBox, MBBox: TBox;

MSBox:=IntToBox(MSX1, MSY1, MSX2, MSY2);
MMBox:=IntToBox(MMX1, MMY1, MMX2, MMY2);
MIBox:= IntToBox(MIX1, MIY1, MIX2, MIY2);
MCBox:= IntToBox(MCX1, MCY1, MCX2, MCY2);
MBBox:= IntToBox(MBX1, MBY1, MBX2, MBY2);

Sir R. M8gic1an

2010-06-11 18:40:16

From: MylesMadness
That doesn't make any sence, why not make it:

{ MainScreen, Minimap, Inventory, Chat, Bank boxes as TBox }
var
MSBox, MMBox, MIBox, MCBox, MBBox: TBox;

MSBox:=IntToBox(MSX1, MSY1, MSX2, MSY2);
MMBox:=IntToBox(MMX1, MMY1, MMX2, MMY2);
MIBox:= IntToBox(MIX1, MIY1, MIX2, MIY2);
MCBox:= IntToBox(MCX1, MCY1, MCX2, MCY2);
MBBox:= IntToBox(MBX1, MBY1, MBX2, MBY2);


indeed :duh:

~RM

Bad Boy JH

2010-06-12 07:06:34

or why not constants? (Can you declare TBoxes as constants?)

NCDS

2010-06-12 13:56:31

From: EvilChicken!
Now to make all color searching functions accept TBoxes as params..


or just use TBox.x1, TBox.y1 etc.?

I like this addition.

Nava2

2010-06-12 14:54:50

I like this addition as well, but Myles definitely has it right ;)

I was curious why you had it as functions myself.

I wish we could have a dynamically typed language where we could just have the same params and pass it. :(

EvilChicken!

2010-06-13 07:12:43

From: NCDS
or just use TBox.x1, TBox.y1 etc.?

I like this addition.


.. what is the real point of writing "FindColor(Tro, lolo, TBox.x1, TBox.y1, ect.." when that just extends the length of the code?
Or am I missing something here?

I like this update too, that's not it; I just think it'd be nice if such functions could accept TBoxes as well, would save some time writing those damn coords over and over again.

Sir R. M8gic1an

2010-06-13 08:20:34

From: EvilChicken!
.. what is the real point of writing "FindColor(Tro, lolo, TBox.x1, TBox.y1, ect.." when that just extends the length of the code?
Or am I missing something here?

I like this update too, that's not it; I just think it'd be nice if such functions could accept TBoxes as well, would save some time writing those damn coords over and over again.


Just wrap them.. that's what I do in my scripts…

~RM

NCDS

2010-06-13 11:06:24

From: EvilChicken!
.. what is the real point of writing "FindColor(Tro, lolo, TBox.x1, TBox.y1, ect.." when that just extends the length of the code?
Or am I missing something here?

I like this update too, that's not it; I just think it'd be nice if such functions could accept TBoxes as well, would save some time writing those damn coords over and over again.

Yes that's fine, I just thought you were sarcastically saying we needed to make the params take TBoxes for this to work. My apologies.