SRL Archive - SRL Snippets

getFreeSlots


KeepBotting

2014-08-06 12:24:41

getFreeSlots() returns a TIntegerArray of the free backpack slots (1-28).
To only return the integer amount of free backpack slots, length(getFreeSlots()) can be used.

function getFreeSlots():TIntegerArray;
var
i:integer;
theArray:TIntegerArray;
begin
if (not gameTabs.isTabActive(TAB_BACKPACK)) then
gameTabs.openTab(TAB_BACKPACK);

for i := BACKPACK_SLOT_LOW to BACKPACK_SLOT_HIGH do
begin
if (not tabBackpack.isItemInSlot(i)) then
begin
theArray.append(i);
end;
end;
writeLn('Free backpack slots are: ' + toStr(theArray));
result := theArray;
end;

rj

2014-08-06 13:22:10

function getFreeSlots():TIntegerArray;
var
i:integer;
begin
gameTabs.openTab(TAB_BACKPACK);

for i := BACKPACK_SLOT_LOW to BACKPACK_SLOT_HIGH do
if (not tabBackpack.isItemInSlot(i)) then
result.append(i);

writeLn('Free backpack slots are: ' + toStr(theArray));
end;

Shortened :p nice function though

KeepBotting

2014-08-06 16:34:23

Thanks :)
From: Robert
function getFreeSlots():TIntegerArray;
var
i:integer;
begin
gameTabs.openTab(TAB_BACKPACK);

for i := BACKPACK_SLOT_LOW to BACKPACK_SLOT_HIGH do
if (not tabBackpack.isItemInSlot(i)) then
result.append(i);

writeLn('Free backpack slots are: ' + toStr(theArray));
end;

Shortened :p nice function though

bonsai

2014-08-07 04:57:26

From: KeepBotting
Thanks :)


Why not make it a backpack function?

function TRSTabBackpack.getFreeSlots():TIntegerArray;
var
i:integer;
begin
gameTabs.openTab(TAB_BACKPACK);

for i := BACKPACK_SLOT_LOW to BACKPACK_SLOT_HIGH do
if (not self.isItemInSlot(i)) then
result.append(i);

writeLn('Free backpack slots are: ' + toStr(theArray));
end;

KeepBotting

2014-08-07 07:22:55

From: bonsai
Why not make it a backpack function?

function TRSTabBackpack.getFreeSlots():TIntegerArray;
var
i:integer;
begin
gameTabs.openTab(TAB_BACKPACK);

for i := BACKPACK_SLOT_LOW to BACKPACK_SLOT_HIGH do
if (not self.isItemInSlot(i)) then
result.append(i);

writeLn('Free backpack slots are: ' + toStr(theArray));
end;

True :P it's more to type tabBackpack.getFreeSlots() though

bonsai

2014-08-07 10:57:03

From: KeepBotting
True :P it's more to type tabBackpack.getFreeSlots() though


tabBackpack is a variable of type TRsTabBackpack so if you did it as above you would indeed call it as tabBackpack.getFreeSlots()

var tabBackpack: TRSTabBackpack;