SRL Archive - OSR Help

Help compileing a function


Troll

2011-02-14 11:01:36

So ive qucikly made a function of looking though the reflection inclued for my scirpt im making which is a mining guild.

So its meant to have the tile of a rock, and check if poeple are near it by checking the 4 tiles around it, N E S W cuz cant mine from top right and stuff. Then check it they are mining, then check if they are mining on that rock.

Any help to compile if it would work and the such would be great thanks.


Function CheckRock(TileX:TTile):Boolean;
Var PlayerArray,PlayersNearRock:TPlayerArray;
I:Integer;
PointT :TPoint;
a,b,c,d:TTile;
Begin

If Not LoggedIn Then Exit;
writeln('Starting - CheckRock');

PointT := TileToPoint(TileX)
a := Tile((PointT.x+1),PointT.y)
b := Tile((PointT.x),(PointT.y+1))
c := Tile((PointT.x-1),PointT.y)
d := Tile(PointT.x,(PointT.y-1))
PlayerArray := GetAllPlayers

For I:=0 To High(PlayerArray) Do
Begin
If (PlayerArray[I].Tile = A) Or (PlayerArray[I].Tile = B) Or (PlayerArray[I].Tile = C) Or (PlayerArray[I].Tile = D) Then
Begin
PlayersNearRock := PlayersNearRock + PlayerArray[I]
writeln('CheckRock - Added player to an array');
End;
End;
//Not sure what it is :(
If High(PlayersNearRock) = 0 or -1 Then
Begin
Result := True
writeln('No players found near rock');
Exit;
End;

For I:= 0 To High(PlayersNearRock) Do
Begin
If (GetAnimation = -1) Then
PlayersNearRock := PlayersNearRock - PlayersNearRock[I]
End;

If High(PlayersNearRock < 0 ) Then
Begin
writeln('CheckRock - No players left in array');
Result := True
Exit;
End;

For I:= High(PlayersNearRock) DownTo 0 Do
Begin
If PlayersNearRock[I].Tile = a Then
If PlayersNearRock[I].Orientation = 90 Then
Begin
writeln('Player facing rock and animating dang :(');
Result := False
Exit;
End;
If PlayersNearRock[I].Tile = b Then
If PlayersNearRock[I].Orientation = 0 Then
Begin
writeln('Player facing rock and animating dang :(');
Result := False
Exit;
End;
If PlayersNearRock[I].Tile = c Then
If PlayersNearRock[I].Orientation = 270 Then
Begin
writeln('Player facing rock and animating dang :(');
Result := False
Exit;
End;
If PlayersNearRock[I].Tile = d Then
If PlayersNearRock[I].Orientation = 180 Then
Begin
writeln('Player facing rock and animating dang :(');
Result := False
Exit;
End;
End;
End;

Thanks :)

HyperSecret

2011-02-14 11:24:08

What does it say when you are trying to compile? Do you get any errors?

Troll

2011-02-14 11:30:38

Yh i do get errors :(
The first one i get is this line

writeln('CheckRock - Added player to an array');

[Error] (42:7): Type mismatch at line 41
And im sure there is more further in

Hobbit

2011-02-14 11:45:11

First problem is the lind above the writeln is missing a ;

Second is you have playersnearrock declared as a TPlayerArray and then you go and try to assign tile values to it. Change it to a TTileArray or the equivalent.

Troll

2011-02-14 11:58:22

Umm where do i try to use a tile to it, i thought i was using the player type?

HyperSecret

2011-02-14 12:12:32


PlayersNearRock := PlayersNearRock + PlayerArray[I]

You don't add to arrays in this manner. That is like doing 'Cars = Cars + Bikes;' you can't add two totally different things.

Here you are adding an array element and an array, just doesn't work.

You need to learn more about arrays from a tutorial around here. It should be added like…


SetLength(array, GetArrayLength + 1);
array[index] = item to be inserted;
//etc.. or something like that, look into it

Hope this helps

Troll

2011-02-14 13:26:03

Thanks that works great i have it compileing now, all i need to do is test it :)