PDA

View Full Version : TReflectInvItem.count



rj
01-23-2015, 04:22 AM
function TReflectInvItem.count(item:variant):integer;
var
T:TReflectInvItemArray;
i:integer;
begin
T.get(item);
if (length(T) < 0) then
exit(0);
if (Reflect.Misc.VariantIsString(item)) then
begin
for i := 0 to high(T) do
if (T[i].name = item) then
result := result + 1;
end
else
begin
for i := 0 to high(T) do
if (T[i].name = item) then
result := result + 1;
end;
end;

counts the number of a item in your inventory.

The Mayor
01-23-2015, 04:42 AM
Isn't the for loop in the else block exactly the same?

Turpinator
01-23-2015, 07:02 AM
Isn't the for loop in the else block exactly the same?

Looks like it. if if he would just call it as const, you dont need to worry about making sure it fits the variant type, and could do whatever.

or instead of variant type, could just make overloads to reduce the logic required in it and let the interpreter take care of it.

akarigar
01-23-2015, 07:28 AM
I'm not sure how we overlooked this! We will be adding this feature soon.

rj
01-23-2015, 05:01 PM
Looks like it. if if he would just call it as const, you dont need to worry about making sure it fits the variant type, and could do whatever.

or instead of variant type, could just make overloads to reduce the logic required in it and let the interpreter take care of it.

I only did it because that's how it was done in the include

Kyle
01-23-2015, 05:37 PM
I only did it because that's how it was done in the include

Ahh, but the include does it correctly ;)

If you pass a ID to your function it will error, I think that was their point. You compare the Name = Item both times. If it is an Id it will try to compare a string to an int, erroring out. You need to make it T[I].Id = Item on the second loop