Item in backpack
Moderator: POL Developer
Item in backpack
How to check whether the item is located in backpack?
Re: Item in backpack
Code: Select all
Var cont:=item.container;
While (cont)
cont:=cont.container;
Endwhile
If cont==chr
...
Re: Item in backpack
If you only want to check if the item is in the backpack you just check with
but if you want to check all the sub containers aswell you have to follow Turleys advice and loop through them
Code: Select all
if ( item.container == character.backpack )
Re: Item in backpack
also you can use something like this:
/code]
Code: Select all
function IsOnBackPack (chr, item)
if(!item.container)
return 0;
elseif(item.container == chr.backpack)
return 1;
else
return IsOnBackPack(chr, item.container);
endif
endfunction
Re: Item in backpack
Tericob its better to do a while loop than have a function call itself repeatedly because it will take up more memory and processing going further into call depth. Your script also has the possibility of reaching maximum call depth in the worst case scenario which will halt the script entirely.
This code should work perfect for you.
Code: Select all
function IsInBackpack(item, backpack)
while (item.container)
if (item.container == backpack)
return 1;
endif
item := item.container;
endwhile
return 0;
endfunction