SRL Archive - Reflection Help

add to an array


fre

2011-08-02 07:28:52

Hey all,

i would like to add a tile to an TileArray
but when i use the code below( this is not the whole code) i get a "type mismatch" error.

Can anyone teach me how to add tiles to an already existing array of tiles?



var
objs:TRSObjectArray;
ChosenTiles : TTileArray;
i:integer;
begin
objs := R_GetObjectsEX([.....], ., ..);
for i := 0 to high (objs) do
begin
WalkPath([objs[i].tile])
ChosenTiles := ChosenTiles + objs[i].tile <-------------
end;

end;

Help would be greatly appreciated.

Home

2011-08-02 07:43:33

I think you could try to combine them?



Some pseudo code.

program new;
var

CombArr, SecondArr, FirstArr : TIntegerArray;

Procedure Test;
begin
FirstArr := [1, 8]
SecondArr := [2, 4]
CombArr := CombineIntArray(FirstArr, SecondArr)
Writeln(ToStr(CombArr));
end;



begin
Test;
end.

Edit: I try to make somekind of function for you.

fre

2011-08-02 07:47:11

Thx for the reply,

And that is exactly what i need, but instead of integers i need it for tiles.
but how do i combine tile arrays?
CombineTileArray or CombineTTileArray does not work.

masterBB

2011-08-02 07:51:36

var
objs:TRSObjectArray;
ChosenTiles : TTileArray;
i:integer;
begin
objs := R_GetObjectsEX([.....], ., ..);
for i := 0 to high (objs) do
begin
WalkPath([objs[i].tile])
setLength(ChosenTiles,Length(ChosenTiles) +1);
ChosenTiles[High(ChosenTiles)] := objs[i].tile; <-------------
end;

end;

Home

2011-08-02 07:57:06

function AddTTileArrays(FirstArr, SecondArr: TTileArray): TTileArray;
var
x, y, z: Integer;
begin
x:= Length(FirstArr);
y:= Length(SecondArr);
SetArrayLength(Result, X + Y);

for Z:= 0 to High(FirstArr) do
Result[Z]:= FirstArr[Z];

for Z:= 0 to y -1 do
Result[(X + Y) - (Y - Z)]:= SecondArr[Z];
end;

Procedure TestArrays;
Var
FirstArr, SecondArr :TTileArray;
begin
FirstArr:=[Point(1245, 8376), Point(1128, 1334)]
SecondArr:=[Point(9823, 1923)]
Writeln(ToStr(AddTTileArrays(FirstArr, SecondArr)))
end;


Have fun ;)


Edit: Ninjaed :P
~Home

masterBB

2011-08-02 08:01:14

This: [(X + Y) - (Y - Z)]
equals: [X + Z]

Home

2011-08-02 08:04:23

From: masterBB
This: [(X + Y) - (Y - Z)]
equals: [X + Z]


Who cares :P

Joke :)


~Home

BraK

2011-08-02 08:09:36

[OFFTOPIC]

Fre the Pic in your sig is killing my internet :( you really should get rid of it.

~BraK

fre

2011-08-02 08:42:42

Actually adding,combing TTile arrays is as easy as


var
a,b,c : TTileArray;
begin
a := b + c
end;

but what if i want to add 1 tile to a TTile array
like tis


var
a,b : TTileArray;
c : TTile; (or TPoint, dont rly know the difference)
begin
a:=b+c; <------------ gives me type mismatch
end;

EDIT: i think i got it thx to Home !!

var
i:integer;
a,b : TTileArray;
c : TTile; (or TPoint, dont rly know the difference)
begin
for i := 0 to high (c) do <-------- this makes the TTile into an TTile array am i right?
Result(i) := c(i);
a:=b+c; <------------does NOT gives me type mismatch
end;

fre

2011-08-02 09:07:48

So that was the start of the procedure.
Now i want to find for a RSObjectArray but excluding the RSObjects with the tiles in the TTileArray i already found.

global var
a : TTileArray;


var
i:integer;
a,b : TTileArray;
c : TTile; (or TPoint, dont rly know the difference)
begin
for i := 0 to high (c) do <-------- this makes the TTile into an TTile array am i right?
Result(i) := c(i);
a:=b+c; <------------does NOT gives me type mismatch
end;



procedure findobjwithouttilesalreadyfound;
var
objs : TRSObjectArray;
i : Integer
begin
objs := R_GetObjectsEX(..,..,..)
for i := 0 to high (objs) do
begin
if objs[i].tile <> a then <----- (a is an array so how do i compare single tiles to single tiles out of an array?)
do thisandthat
end;
end;

Home

2011-08-02 09:23:08

So you wan't now something like this.

1. Get Objects tiles
2. Compare all tiles what are NOT in array already to those tiles what you got from objects?

~Home

fre

2011-08-02 09:31:29

yes, indeed,

i want to filter the tiles that already have in my array of tiles out of my array of tiles from the objects.


tile array i already have =Tile1,Tile2
objs tile array = Tile5,Tile3,Tile10,Tile1,Tile9
result = Tile5,Tile3,Tile10,Tile9


So Tile 1 is filtered out of that array

Home

2011-08-02 09:36:29

From: fre
yes, indeed,

i want to filter the tiles that already have in my array of tiles out of my array of tiles from the objects.


tile array i already have =Tile1,Tile2
objs tile array = Tile5,Tile3,Tile10,Tile1,Tile9
result = Tile5,Tile3,Tile10,Tile9


So Tile 1 is filtered out of that array


Is there possibility that I could see whole code. My English understanding is lacking off quite a bit :)


EDIT:
Couldnt you do this Combine Both Arrays. Then ClearSameIntegers?

~Home

masterBB

2011-08-02 09:41:45

Wait a minute… This shouldn't work.

var
i:integer;
a,b : TTileArray;
c : TTile; (or TPoint, dont rly know the difference)
begin
for i := 0 to high (c) do <-------- this makes the TTile into an TTile array am i right?
Result(i) := c(i);
a:=b+c; <------------does NOT gives me type mismatch
end;

c is a TTile variable. It doesn't got a high result. Have really tested this? Cause at my laptop it returns an error.

Also what is wrong with just setting the length one higher and adding the ttile to the highest array slot as in my example? Even if you want it shorter it would be:

var
i:integer;
a,b : TTileArray;
c : TTile;
begin
a:=b+[c];
end;

edit:
Just use an filter TPA function…

c := ClearTPAFromTPA(a,b);

fre

2011-08-02 09:46:34

Oke, imma try this out in a few minutes and test it, i ll post progress.

Thx for the replies :-)

masterBB

2011-08-02 10:00:54

This is tested:

program new;
{.include SRL/SRL/Misc/SMART.scar}
{.include SRL/SRL.scar}
{.include Reflection/Reflection.simba}

function yourFunct():TTileArray;
var
a,b : TTileArray;
c : TTile;
begin
a := [Point(2,3),Point(7,3),Point(1,3)];
c := Point(5,3);
b := [Point(2,3),Point(3,3)];
Result := [c];
Result := a+Result;
Result := ClearTPAFromTPa(Result,b);
end;

begin
writeln(funct1);
end.

fre

2011-08-02 10:47:10

Looooooool

i can't believe u made it seem so easy :p

thx alot!

~Fre

masterBB

2011-08-02 10:54:47

This one is shorter:

rogram new;
{.include SRL/SRL/Misc/SMART.scar}
{.include SRL/SRL.scar}
{.include Reflection/Reflection.simba}

function yourFunct():TTileArray;
var
a,b : TTileArray;
c : TTile;
begin
a := [Point(2,3),Point(7,3),Point(1,3)];
c := Point(5,3);
b := [Point(2,3),Point(3,3)];
Result := CombineTPA(a,[c]);
Result := ClearTPAFromTPa(Result,b);
end;

begin
writeln(yourFunct);
end.

Note: cause this function is abstract I used the vars a,b and c. But this is bad practice in your script. I suggest you change them to var names that gives more information about the value. Like monsterTiles, badMonsterTiles etc…

Home

2011-08-02 11:21:29

Lol. What I was doing :P?

Why I need to always try some hardest way -.-

~Home

fre

2011-08-03 08:30:56

So it works.

What i need now is this,
i got an array (of tiles) and i want to delete the latest tile in that array.


MyArray := [Point(1111,1111),Point(5555,5555),Point(2222,2222),Point(3333,3333)]
WhatIWant := [Point(1111,1111),Point(5555,5555),Point(2222,2222)]


Easy as this?


SetArrayLength(MyArray,Length(MyArray)-1);

BraK

2011-08-03 08:37:28

Why not just use SetArrayLength(MyArray ,(Length(MyArray) - 1));

Something like that anyway.

~BraK

E: lol this is post count number 1111 :)

Dgby714

2011-08-03 08:52:53

function TA_Push(var TA: TTileArray; const Tile: TTile): LongInt;
begin
Result := Length(TA);
SetLength(TA, Result + 1);
TA[Result] := Tile;
end;

function TA_Pop(var TA: TTileArray): TTile;
var
H: LongInt;
begin
H := High(TA);
if (H = -1) then
Exit;

Result := TA[H];
SetLength(TA, H);
end;