# Thread: [question] array of record

1. SRL Member
Join Date
Oct 2007
Posts
184
Mentioned
7 Post(s)
Quoted
60 Post(s)

## [question] array of record

Having a bit of trouble here. I'm trying to dynamically populate an array of loot objects to make searching for them easier.

Loot record:
Code:
loot = record
name: String;       //stores variables that help find loot
overText: TStringArray;    //mouseovertext of loot
colours: T2DColorData;        //colours of loot
end;
when I initiate the objects of loot record, I set pointer to 0 ( x := 0) then try to add them to the array like this
Code:
dragonBones.init('Dragon Bones', ['ake', 'dragon', 'bones'], [[12698835, 5, [2, [0.93, 0.45, 0.00]]], [12106698, 5, [2, [0.31, 0.64, 0.00]]]]);
lootArray[x] := dragonBones;
inc(x);
then I want to search for them with this:
Code:
for x to high(lootArray) do
begin
if players[currentPlayer].booleans[_DEBUG] then
writeLn('Looking for ',lootArray[x].name, ' ...');
if lootArray[x].find(false) then
begin
if players[currentPlayer].booleans[_DEBUG] then
writeLn('Found ',lootArray[x].name, ' !!');
clickedLoot := true;
break;
end;
end;
I believe I'm not populating the array correctly. Could anyone chime in with some advice? Much appreciated

2. Originally Posted by klamor
...
How is 'lootarray' defined? What's its length?

3. SRL Member
Join Date
Oct 2007
Posts
184
Mentioned
7 Post(s)
Quoted
60 Post(s)
Originally Posted by Citrus
How is 'lootarray' defined? What's its length?
Code:
lootArray: array of loot;
how do I define it with a dynamic size? or do I need to change it every time I add more loot items?

4. Originally Posted by klamor
Code:
lootArray: array of loot;
how do I define it with a dynamic size? or do I need to change it every time I add more loot items?
The size is dynamic, meaning it can change. It doesn't magically change when you try to access indices that don't exist. It only changes when you tell it to change.
You can use SetLength(), or the '+' operator:
Simba Code:
SetLength(SomeArray, Length(SomeArray) + 1);SomeArray[High(SomeArray)] := NewElement;//orSomeArray := SomeArray + NewElement;
If you're using Simba 1.2 there might be more options available (ask slacky).

Just a little note to make your code more up to standards: your custom types should look something like this:
Simba Code:
type TLoot = record ... end;type TLootArray = Array of TLoot;

5. SRL Member
Join Date
Oct 2007
Posts
184
Mentioned
7 Post(s)
Quoted
60 Post(s)
what's the need for it to be a new type rather than a simple var?

6. Originally Posted by klamor
what's the need for it to be a new type rather than a simple var?
There's no need AFAIK, just like there is no need to use intelligible variable names or indentation. It just helps with readability and organization. imo