Jump to content
shadowrecon

Dividing up the MS

Recommended Posts

Im trying to figure out a way to divide up the ms into a 8x8 block of boxes, ( its for a script so i can do different stuff if clicked within a certain box) i was wondering if you guys had any ideas on it? i started with a bunch of if statements using 64 x positions per box and 42 y positions. The problem is i ended up with 64 different if statements which is a little over then top, i figure there has to be much better way, so i then ended up using the point in box functions and made 64 boxes but i was wondering if anyone has any simpler methods?

 

Here is what i have:

Function FindMSBox(Var MSBox:TBox; P:TPoint):Boolean;
Var
I,II:Integer;
B: Array [0..63] of TBox;
begin
II := 0;
for I:= 0 to 7 do
begin
B[i] := Box(0+II,0,65+II,42);
IncEx(II,65);
end;
II := 0;
for I:= 8 to 15 do
begin
B[i] := Box(0+II,42,65+II,84);
IncEx(II,65);
end;
II := 0;
for I:= 16 to 23 do
begin
B[i] := Box(0+II,84,65+II,126);
IncEx(II,65);
end;
II := 0;
for I:= 24 to 31 do
begin
B[i] := Box(0+II,126,65+II,168);
IncEx(II,65);
end;
II := 0;
for I:= 32 to 39 do
begin
B[i] := Box(0+II,168,65+II,210);
IncEx(II,65);
end;
II := 0;
for I:= 40 to 47 do
begin
B[i] := Box(0+II,210,65+II,252);
IncEx(II,65);
end;
II := 0;
for I:= 48 to 55 do
begin
B[i] := Box(0+II,252,65+II,294);
IncEx(II,65);
end;
II := 0;
for I:= 56 to 63 do
begin
B[i] := Box(0+II,294,65+II,336);
IncEx(II,65);
end;
I := 0;
repeat
if PointInBox(P,B[i]) then
Begin
MSBox := B[i];
Result := True;
end else
inc(i);
if I > 63 then
begin
Result := False;
Break;
end;
until Result = True;
end; [/Code]

 

Here is what it looks like debugged

[ATTACH=CONFIG]285[/ATTACH]

Edited by shadowrecon
Link to comment
Share on other sites

ATPA := TPAToATPA(MSPW div 8, MSPH div 8);

 

If that's not working for you

 

{$DEFINE RS2}

{$I OSI\OSI.scar}
{$I OSI\Divi\Misc\Debug.scar}

procedure ScriptTerminate;
begin
 FreeOSI;
end;

var
 I: Integer;
 TBA: TBoxArray;

begin
 SetUpOSI;
 SetLength(TBA, 64);
 for I := 0 to 63 do
   TBA[i] := Box(Round(MSX1 + ((I mod 8) * (MSPW / 8))), Round(MSY1 + ((I div 8) * (MSPH / 8))), Round(MSX1 + (MSPW / 8) + ((I mod 8) * (MSPW / 8))), Round(MSY1 + (MSPH / 8) + ((I div 8) * (MSPH / 8))));
 DebugTBA(TBA);
end.

 

FindColor(...TBA.X1, TBA.Y1

Edited by Wanted
Link to comment
Share on other sites

ATPA := TPAToATPA(MSPW div 8, MSPH div 8);

 

If that's not working for you

 

{$DEFINE RS2}

{$I OSI\OSI.scar}
{$I OSI\Divi\Misc\Debug.scar}

procedure ScriptTerminate;
begin
 FreeOSI;
end;

var
 I: Integer;
 TBA: TBoxArray;

begin
 SetUpOSI;
 SetLength(TBA, 64);
 for I := 0 to 63 do
   TBA[i] := Box(Round(MSX1 + ((I mod 8) * (MSPW / 8))), Round(MSY1 + ((I div 8) * (MSPH / 8))), Round(MSX1 + (MSPW / 8) + ((I mod 8) * (MSPW / 8))), Round(MSY1 + (MSPH / 8) + ((I div 8) * (MSPH / 8))));
 DebugTBA(TBA);
end.

 

FindColor(...TBA.X1, TBA.Y1

 

That is what i was looking for, i didnt notice you had posted this before i went through and made my own version.. ugh.. yous is a lot cleaner and a heck of alot less lines.. Thanks man.

Edited by shadowrecon
Link to comment
Share on other sites

That is what i was looking for, i didnt notice you had posted this before i went through and made my own version.. ugh.. yous is a lot cleaner and a heck of alot less lines.. Thanks man.

 

Keep in mind that's not the best way, if you were doing something that involved thousands of iterations you could cut down on the number of redundant evaluations more by storing those values to variables, but this should work in much less than 1 ms for anything you're doing... plus yea it's just '1 line'.

Link to comment
Share on other sites

Keep in mind that's not the best way, if you were doing something that involved thousands of iterations you could cut down on the number of redundant evaluations more by storing those values to variables, but this should work in much less than 1 ms for anything you're doing... plus yea it's just '1 line'.

Yeah, im trying to let more of the program do all the work and stray away from typing everything in manually.. works a whole lot better. im getting some array errors trying to implement this the way i want to. could you tell me what im setting up wrong here?

 Function FindMSBox(Var MSBox:TBox; P: TPoint):Boolean;
var
 I: Integer;
 TBA: TBoxArray;
begin
 SetLength(TBA, 64);
 for I := 0 to 63 do
   TBA[i] := Box(Round(MSX1 + ((I mod 8) * (MSPW / 8))), Round(MSY1 + ((I div 8) * (MSPH / 8))), Round(MSX1 + (MSPW / 8) + ((I mod 8) * (MSPW / 8))), Round(MSY1 + (MSPH / 8) + ((I div 8) * (MSPH / 8))));

 for I := 0 to 63 do
   if PointInBox(P,TBA[i]) then
     Begin
       MSBox := TBA[i];
       Result := True;
       Exit;
     end;
 result := False;
end;

 

---------- Post added at 05:34 AM ---------- Previous post was at 05:29 AM ----------

 

Nvm, i wasnt setting up osi in my main begin loop ... stupid error.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...