Item in backpack

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
n3k
New User
Posts: 5
Joined: Sun Aug 21, 2011 1:58 am

Item in backpack

Post by n3k »

How to check whether the item is located in backpack?
Turley
POL Developer
Posts: 670
Joined: Sun Feb 05, 2006 4:45 am

Re: Item in backpack

Post by Turley »

Code: Select all

Var cont:=item.container;
While (cont)
cont:=cont.container;
Endwhile
If cont==chr
 ...
Something like that
Tomi
POL Developer
Posts: 478
Joined: Tue Feb 21, 2006 5:08 pm

Re: Item in backpack

Post by Tomi »

If you only want to check if the item is in the backpack you just check with

Code: Select all

if ( item.container == character.backpack )
but if you want to check all the sub containers aswell you have to follow Turleys advice and loop through them
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

Re: Item in backpack

Post by Terciob »

also you can use something like this:

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
/code]
User avatar
CWO
POL Expert
Posts: 1159
Joined: Sat Feb 04, 2006 5:49 pm

Re: Item in backpack

Post by CWO »

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.

Code: Select all

function IsInBackpack(item, backpack)
     while (item.container)
          if (item.container == backpack)
               return 1;
          endif
          item := item.container;
     endwhile
     return 0;
endfunction
This code should work perfect for you.
Post Reply