SRL Archive - Help and Support

Counting Inv Locations


WhoCares357

2007-12-22 18:01:33

I haven't tried Scar in a long time, and I was just trying to remember a few things. Anyways, I tried making an inventory procedure. It was supposed to define each inventory record with a coord numbers (location of it with x1, y1, x2, y2). I set up the following script. (I'm not finished with the procedure yet. I only set up the counting for the first column.)


program Test;

type
Inv=record
x1, y1: Integer;
x2, y2: Integer;
end;

var Inventory: array [1..28] of Inv;
var i: Integer;//counter

procedure SetInvSlots;
begin
for i := 1 to 28 do
begin
i := i + 1;

//Messes up here. This is the counting of the first column.
if (i = 1) or (i = 5) or (i = 9) or (i = 13) or (i = 17)
or (i = 21) or (i = 25) then
begin
Inventory[i].x1 := 563;
Inventory[i].y1 := 185 + (29 * i);
Inventory[i].x2 := 594;
Inventory[i].y2 := 211 + (29 * i);
end else

//I will do the rest later, so I just defined the rest randomly.
begin
Inventory[i].x1 := 1;
Inventory[i].y1 := 2;
Inventory[i].x2 := 3;
Inventory[i].y2 := 4;
end;
end;
end;

begin
SetInvSlots;
i := 1;
repeat
begin //displaying results
WriteLn('x1 slot #' + IntToStr(i) + ': ' + (IntToStr(Inventory[i].x1)));
WriteLn('y1 slot #' + IntToStr(i) + ': ' + (IntToStr(Inventory[i].y1)));
WriteLn('x2 slot #' + IntToStr(i) + ': ' + (IntToStr(Inventory[i].x2)));
WriteLn('y2 slot #' + IntToStr(i) + ': ' + (IntToStr(Inventory[i].y2)));
i := i + 1;
end;
until(i > 28);
end.


When I compile it, this is what I get:

x1 slot #1: 0
y1 slot #1: 0
x2 slot #1: 0
y2 slot #1: 0
x1 slot #2: 1
y1 slot #2: 2
x2 slot #2: 3
y2 slot #2: 4
x1 slot #3: 0
y1 slot #3: 0
x2 slot #3: 0
y2 slot #3: 0
x1 slot #4: 1
y1 slot #4: 2
x2 slot #4: 3
y2 slot #4: 4
x1 slot #5: 0
y1 slot #5: 0
x2 slot #5: 0
y2 slot #5: 0
x1 slot #6: 1
y1 slot #6: 2
x2 slot #6: 3
y2 slot #6: 4
x1 slot #7: 0
y1 slot #7: 0
x2 slot #7: 0
y2 slot #7: 0
x1 slot #8: 1
y1 slot #8: 2
x2 slot #8: 3
y2 slot #8: 4
x1 slot #9: 0
y1 slot #9: 0
x2 slot #9: 0
y2 slot #9: 0
x1 slot #10: 1
y1 slot #10: 2
x2 slot #10: 3
y2 slot #10: 4
x1 slot #11: 0
y1 slot #11: 0
x2 slot #11: 0
y2 slot #11: 0
x1 slot #12: 1
y1 slot #12: 2
x2 slot #12: 3
y2 slot #12: 4
x1 slot #13: 0
y1 slot #13: 0
x2 slot #13: 0
y2 slot #13: 0
x1 slot #14: 1
y1 slot #14: 2
x2 slot #14: 3
y2 slot #14: 4
x1 slot #15: 0
y1 slot #15: 0
x2 slot #15: 0
y2 slot #15: 0
x1 slot #16: 1
y1 slot #16: 2
x2 slot #16: 3
y2 slot #16: 4
x1 slot #17: 0
y1 slot #17: 0
x2 slot #17: 0
y2 slot #17: 0
x1 slot #18: 1
y1 slot #18: 2
x2 slot #18: 3
y2 slot #18: 4
x1 slot #19: 0
y1 slot #19: 0
x2 slot #19: 0
y2 slot #19: 0
x1 slot #20: 1
y1 slot #20: 2
x2 slot #20: 3
y2 slot #20: 4
x1 slot #21: 0
y1 slot #21: 0
x2 slot #21: 0
y2 slot #21: 0
x1 slot #22: 1
y1 slot #22: 2
x2 slot #22: 3
y2 slot #22: 4
x1 slot #23: 0
y1 slot #23: 0
x2 slot #23: 0
y2 slot #23: 0
x1 slot #24: 1
y1 slot #24: 2
x2 slot #24: 3
y2 slot #24: 4
x1 slot #25: 0
y1 slot #25: 0
x2 slot #25: 0
y2 slot #25: 0
x1 slot #26: 1
y1 slot #26: 2
x2 slot #26: 3
y2 slot #26: 4
x1 slot #27: 0
y1 slot #27: 0
x2 slot #27: 0
y2 slot #27: 0
x1 slot #28: 1
y1 slot #28: 2
x2 slot #28: 3
y2 slot #28: 4


What I'm confused about is why all the declarations for the first column turned into 0.

Sumilion

2007-12-22 18:09:56

Do you mean this ?

{*******************************************************************************
function ItemCoords(i: Integer): TPoint;
By: RsN
Description: Returns X and Y of Specified Inventory Spot
*******************************************************************************}

Or maybe :

{*******************************************************************************
Function InvBox(i :Integer): TBox;
By: WT-Fakawi/Wizzup?
Description: Returns TBox of surrounding Inventory SlotBox
1-2-3-4
5-6-7-8
etc.
*******************************************************************************}

nielsie95

2007-12-22 18:10:53


for i := 1 to 28 do
begin
i := i + 1;

So you're actually doing +2 steps now..
Remove it and it works.

Also, take a look at the functions in SRL as Sumilion said and take a look at TBoxes ;)

WhoCares357

2007-12-22 18:11:17

From: Sumilion
Do you mean this ?

{*******************************************************************************
function ItemCoords(i: Integer): TPoint;
By: RsN
Description: Returns X and Y of Specified Inventory Spot
*******************************************************************************}


Well, I know that, but I just wanted to practice types and arrays. Do you know what the problem is that it turns every other result into 0?

WhoCares357

2007-12-22 18:12:17

From: nielsie95

for i := 1 to 28 do
begin
i := i + 1;

So you're actually doing +2 steps now..
Remove it and it works.

Also, take a look at the functions in SRL as Sumilion said and take a look at TBoxes ;)


Wow… :D. Very stupid mistake. Thank you.