SRL Archive - OSR Help

Need help with a procedure.


bud_wis_er_420

2013-04-01 19:06:36

Oh man here we go, this is hard to explain….:duh:

I'm trying to make a procedure that will take an IntegerArray, stored with either 1 or 2 variables and transfer that info to a type integer to be used later. All in one line!!

I keep getting an error: Variable Expected at line 78

I'm assuming it has something to do with trying to pass a variable back threw the procedure into a type variable.

This is the line I want to call…
LoadItems(['CopperOre', 'TinOre'], [CopperOre.Amount, TinOre.Amount], [14, 14]); 

'CopperOre.Amount' and 'TinOre.Amount' I want to both equal 14 after the above line is called(If it worked that is).

Another example with the array only having a length of one…
LoadItems(['GoldOre'], [GoldOre.Amount], [28]); 
'GoldOre.Amount' I want to equal 28 after the above line is called(If it worked that is).

All I'm trying to do is set at least 2 type variables to different numbers each all on one line.

Here is the script I made to show you what I'm trying to do.
program new;

type
Item = record
Color, Tol, Bmp, Dtm, Amount, BankLoc: Integer;
Hue, Sat: Extended;
UpText: TStringArray;
end;

var
ItemsNeed: TStringArray;
CopperOre, TinOre : Item;

procedure LoadType;
begin
with CopperOre do
begin
color := 3367856;
Tol := 8;
Hue := 0.02;
Sat := 0.26;
UpText := ['Copper ore', 'pper or', 'per ore'];
Bmp := BitmapFromString(7, 8, 'meJzTsvVlYmAwNjYGkhreLfqRc40T' +
'VurY+8MFtfy7IYK6joFwQZ3gyRBBfZcwuKBe2AzDmEUmSWsN3SLgg' +
'gZR84HKzNI2m/knwwUNY5cYJ642Td1k6psIEdQxtgIyjOJXmCSvM/' +
'GORxaEIABTwyQ6');
Dtm := DTMFromString('78DA634C656060106664000108C9C0B03ED99' +
'44109CAFF0F048CB9408624449605979A28843930354E262A0C32' +
'48E632E603093E026A1281842C7E350004CF0F73');
SetBitmapName(CopperOre.Bmp, 'CopperOre.Bmp');
SetDTMName(CopperOre.Dtm, 'CopperOre.Dtm');
Amount := 0;
end;

with TinOre do
begin
color := 5921374;
Tol := 6;
Hue := 0.56;
Sat := 0.09;
UpText := ['Tin ore', 'in ore'];
Bmp := BitmapFromString(9, 9, 'meJxNzmsKwjAQBODiabSo/RFfRVot' +
'ESum6YsQQoi2pfT+V3BgYRGGJezHsIkzvU5fqygSQmDmedG2xlpvj' +
'Nvems1VMUn5JPJ+2BVdnGmmslRE4TNd2gVFpqpqmE7NvJeGqa47XH' +
'EufIf5qKfkYZn63mKPyjguIISJKiC0DmpAiJLzHQ/6HpF4h3+ioPg' +
'Dn+g1tw==');
Dtm := DTMFromString('78DA634C656060106664000108C9C0101715C' +
'52009E5FF0702C65C20431222CB824B4D14C21C981A2713150619' +
'247319F381041F013589404216BF1A00BFBE0EF7');
SetBitmapName(TinOre.Bmp, 'TinOre.Bmp');
SetDTMName(TinOre.Dtm, 'TinOre.Dtm');
Amount := 0;
end;
end;

// Procedure I'm trying to get working
procedure LoadItems(Name: TStringArray; var ItemAmt: TIntegerArray; amt: TIntegerArray);
var
i: Integer;
begin
SetArrayLength(ItemsNeed, High(Name) + 1);
SetArrayLength(ItemAmt, High(Name) + 1);
for i := 0 to High(Name) do
begin
ItemsNeed[i] := Name[i];
ItemAmt[i] := amt[i];
end;
end;

var
TIA: TIntegerArray;
i: Integer;
begin
LoadType;
writeln('Copper Start: ' + IntToStr(CopperOre.Amount));
writeln('Tin Start: ' + IntToStr(TinOre.Amount));

{1 line}
//This is the line I want to call to get the results down below in 1 line
LoadItems(['CopperOre', 'TinOre'], [CopperOre.Amount, TinOre.Amount], [14, 14]);

{3 lines}
//This is only way I can get it to work in 3 lines
{
LoadItems(['CopperOre', 'TinOre'], TIA, [14, 14]);
CopperOre.Amount := TIA[0];
TinOre.Amount := TIA[1];
}

//This will be my results: Should output 14, 14
writeln('Copper End: ' + IntToStr(CopperOre.Amount));
writeln('Tin End: ' + IntToStr(TinOre.Amount));
end.

Le Jingle

2013-04-01 19:26:25

You are not handing back a TIntegerArray variable type, you're making a TIntegerArray defined in the parameters only, thus an error.

bud_wis_er_420

2013-04-01 19:38:46

From: Le Jingle
You are not handing back a TIntegerArray variable type, you're making a TIntegerArray defined in the parameters only, thus an error.


Sry but that statement was a little over my head. But I'll take your word for it. So then, how could I do what I'm trying to do.

I don't know the terminology but, how do I define, declare, handback 2 sets of numbers to 2 differnet type vars?

Here is a smaller example of what I'm trying to do…
program new;

type
Item = record
Amount: Integer;
end;

var
ItemOne, ItemTwo: Item;

procedure LoadItems(var ItemAmt: TIntegerArray; amt: TIntegerArray);
var
i: Integer;
begin
SetArrayLength(ItemAmt, 2);
for i := 0 to 2 do
ItemAmt[i] := amt[i];
end;

begin
LoadItems([ItemOne.Amount, ItemTwo.Amount], [14, 14])
writeln('ItemOne End: ' + IntToStr(ItemOne.Amount));
writeln('ItemTwo End: ' + IntToStr(ItemTwo.Amount));
end.

bud_wis_er_420

2013-04-01 21:35:19

Anybody else?

Le Jingle

2013-04-01 23:13:36

From: bud_wis_er_420
Sry but that statement was a little over my head. But I'll take your word for it. So then, how could I do what I'm trying to do.

I don't know the terminology but, how do I define, declare, handback 2 sets of numbers to 2 differnet type vars?

Here is a smaller example of what I'm trying to do…

program new;

type
Item = record
Amount: Integer;
end;

var
ItemOne, ItemTwo: Item;

procedure LoadItems(var ItemAmt: TIntegerArray; amt: TIntegerArray);
var
i: Integer;
begin
SetArrayLength(ItemAmt, 2);
for i := 0 to 2 do
ItemAmt[i] := amt[i];
end;

begin
LoadItems([ItemOne.Amount, ItemTwo.Amount], [14, 14])
writeln('ItemOne End: ' + IntToStr(ItemOne.Amount));
writeln('ItemTwo End: ' + IntToStr(ItemTwo.Amount));
end.



// var ItemAmt: TIntegerArray;
// ^ ^
// above means you have to assign a variable, of the same type, TIntegerArray,
// to the argument.
//
// when you say, "[some int, some int]" as an argument, you are not allowing
// anything to be handed back, you are simply declaring new values for a
// TIntegerArray, which isn't what is accepted here.
//
// Here, for "var ItemAmt: TIntegerArray" you have to store a pre-defined variable
// that soley has to be declared (it can be defined - which will be over written,
// or undefined - ex just declared as a variable but never assigned value)
//
// Thus, knowing this, we can do something like below:
type
Item = record
Amount: Integer;
end;

var
i: Integer;
Items: array of Item;

procedure LoadItems(ItemAmounts: TIntegerArray);
var
i: Integer;
begin
SetArrayLength(Items, Length(ItemAmounts));
for i := 0 to high(ItemAmounts) do
Items[i].Amount := ItemAmounts[i];
end;

begin
LoadItems([1, 2, 3, 4, 999, 1337]);
for i := 0 to high(Items) do
Writeln('Item ' + IntToStr(i) + ': ' + IntToStr(Items[i].Amount) + '...');
end.

bud_wis_er_420

2013-04-02 00:03:51

OK I understand now. Thanks very much.