SRL Archive - Reflection Development

DumpInv - Debugging the Inventory made easy


3Garrett3

2010-06-06 18:29:48

So I couldn't find anything in the include to help me find out the IDs and such of my inventory. I was encouraged to go on RSBot or find the GE ids, but I'm really lazy, and since there was a DumpNPCs function laying around, I've modified it to output the TInvItem record.


Procedure DumpInv;
var
i : Integer;
Inv : TInvItem;
begin
for i := 1 to 28 do
begin
if R_ItemExists(i) then
begin
Inv := GetInvItemAt(i);
Writeln('Slot: '+ ToStr(i));
Writeln(' '+'Name: '+Inv.Name);
Writeln(' '+'ID: '+ToStr(Inv.ID));
Writeln(' '+'Actions: '+ ToStr(Inv.Actions));
Writeln(' '+'StackSize: '+ ToStr(Inv.StackSize));
end;
end;
end;

That should do the trick, no?

It outputs

[php]
Slot: 1
Name: Coins
ID: 995
Actions: ['Drop', 'Examine']
StackSize: 92123
Slot: 2
Name: Fishing rod
ID: 307
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 3
Name: Fishing bait
ID: 313
Actions: ['Drop', 'Examine']
StackSize: 400
Slot: 4
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 5
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 6
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 7
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 8
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 9
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 10
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 11
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 12
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 13
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 14
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 15
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 16
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 17
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 18
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 19
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 20
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 21
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 22
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 23
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 24
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 25
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 26
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 27
Name: Raw herring
ID: 345
Actions: ['Drop', 'Examine']
StackSize: 1
Slot: 28
Name: Raw sardine
ID: 327
Actions: ['Drop', 'Examine']
StackSize: 1
[/php]

After my fishing script has done its job. So it seems to work to me.

i luffs yeww

2010-06-06 18:44:34

Seems like a bit much. Maybe have a DumpInv and DumpInvEx? Or DumpInv(True/False)? DumpInvEx would be the version you have no and DumpInv would be a more condensed version. DumpInv(True) would be extended, DumpInv(False) would be condensed.

[PHP]
procedure DumpInvEx;
var
i: Integer;
Inv: TInvItem;
begin
for i := 1 to 28 do
if(R_ItemExists(i))then
begin
Inv := GetInvItemAt(i);
Writeln('Slot: ' + ToStr(i));
Writeln(' ' + 'Name: ' + Inv.Name);
Writeln(' ' + 'ID: ' + ToStr(Inv.ID));
Writeln(' ' + 'Actions: ' + ToStr(Inv.Actions));
Writeln(' ' + 'StackSize: ' + ToStr(Inv.StackSize));
end;
end;

procedure DumpInv;
var
i: Integer;
Inv: TInvItem;
begin
for i := 1 to 28 do
if(R_ItemExists(i))then
begin
Inv := GetInvItemAt(i);
Writeln('Slot ' + ToStr(i) + '; Name: ' + Inv.Name + '; ID: ' + ToStr(Inv.ID) +
'; Actions: ' + ToStr(Inv.Actions) + '; StackSize: ' + ToStr(Inv.StackSize));
end;
end;
[/PHP]

YoHoJo

2010-06-06 18:45:39

Love it. I can't wait to start learning reflection.

I was completely away from SRL during the whole reflection era and never got to use a reflection script or learn to script using reflection.

3Garrett3

2010-06-06 18:52:05

From: i luffs yeww
Seems like a bit much. Maybe have a DumpInv and DumpInvEx? Or DumpInv(True/False)? DumpInvEx would be the version you have no and DumpInv would be a more condensed version. DumpInv(True) would be extended, DumpInv(False) would be condensed.

[PHP]
procedure DumpInvEx;
var
i: Integer;
Inv: TInvItem;
begin
for i := 1 to 28 do
if(R_ItemExists(i))then
begin
Inv := GetInvItemAt(i);
Writeln('Slot: ' + ToStr(i));
Writeln(' ' + 'Name: ' + Inv.Name);
Writeln(' ' + 'ID: ' + ToStr(Inv.ID));
Writeln(' ' + 'Actions: ' + ToStr(Inv.Actions));
Writeln(' ' + 'StackSize: ' + ToStr(Inv.StackSize));
end;
end;

procedure DumpInv;
var
i: Integer;
Inv: TInvItem;
begin
for i := 1 to 28 do
if(R_ItemExists(i))then
begin
Inv := GetInvItemAt(i);
Writeln('Slot ' + ToStr(i) + '; Name: ' + Inv.Name + '; ID: ' + ToStr(Inv.ID) +
'; Actions: ' + ToStr(Inv.Actions) + '; StackSize: ' + ToStr(Inv.StackSize));
end;
end;
[/PHP]


Well I was just formatting mine the same as it is formatted in the DumpNPCs, to stay with similar formats. But either way works, really.

From: YoHoJo
Love it. I can't wait to start learning reflection.

I was completely away from SRL during the whole reflection era and never got to use a reflection script or learn to script using reflection.


:) If you have any questions, you have my msn ;)

i luffs yeww

2010-06-06 18:53:27

:p Well if DumpNPCs is formated the same, then go for it. I don't really care, I just thought it was a bit much.

3Garrett3

2010-06-06 18:56:41

From: i luffs yeww
:p Well if DumpNPCs is formated the same, then go for it. I don't really care, I just thought it was a bit much.


Yeah, I find a vertical list easier to read. I can't commit to Ref anyway, which is why I put it here. Drags or any reflection dev can do what they please with it.

Nava2

2010-06-06 21:28:37

I will add the first when I get time, unless someone else does.

@ian.:
Writeln(Format('Slot %d; Name: %s; ID: %d; Actions: %s; StackSize: %d', [i, Inv.ID, Inv.Actions, Inv.StackSize]));

i luffs yeww

2010-06-07 01:25:07

^ Snazy.

Nava2

2010-06-07 12:37:05

Committed.

3Garrett3

2010-06-07 13:45:44

From: Nava2
Committed.


Yay I did something good :)

Sir R. M8gic1an

2010-06-07 14:46:15

Nava, what's the difference between %d and %s, an what else can you use?

~RM

3Garrett3

2010-06-07 15:14:56

From: Rasta Magician
Nava, what's the difference between %d and %s, an what else can you use?

~RM


Isn't %I include? Or did I just make that up in my head?

MylesMadness

2010-06-07 15:34:02

From: Rasta Magician
Nava, what's the difference between %d and %s, an what else can you use?

~RM
A copy paste from http://php.net/manual/en/function.sprintf.php

b - the argument is treated as an integer, and presented as a binary number.
c - the argument is treated as an integer, and presented as the character with that ASCII value.
d - the argument is treated as an integer, and presented as a (signed) decimal number.
e - the argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less).
E - like %e but uses uppercase letter (e.g. 1.2E+2).
u - the argument is treated as an integer, and presented as an unsigned decimal number.
f - the argument is treated as a float, and presented as a floating-point number (locale aware).
F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). Available since PHP 4.3.10 and PHP 5.0.3.
g - shorter of %e and %f.
G - shorter of %E and %f.
o - the argument is treated as an integer, and presented as an octal number.
s - the argument is treated as and presented as a string.
x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).

3Garrett3

2010-06-07 15:40:24

:\ I was thinking $i, my bad XD

Sir R. M8gic1an

2010-06-07 15:49:40

Thank you myles :)

~RM