Proleric's code actually counts all the items in the container. If all you need to do is determine if there is no more than one item in the container, you could also use
# returns TRUE if there the number of items in the container is 1 or 0, FALSE otherwise.
int bContainsOneOrLess(object oContainer)
{
object oItem = GetFirstItemInInventory(oContainer);
if GetIsObjectValid(oItem) # there is at least one item
{
oItem = GetNextItemInInventory(oContainer);
return !(GetIsObjectValid(oItem); # FALSE if a second item was found
}
return TRUE; # there are zero or one items
}
Which may be slightly faster if there is a possibility of many items in the container.
This isn't what you said, but if you need to know if there is exactly one item (and not zero), then
# returns TRUE if there the number of items in the container is exactly 1, FALSE otherwise.
int bContainsOne(object oContainer)
{
object oItem = GetFirstItemInInventory(oContainer);
if GetIsObjectValid(oItem) # there is at least one item
{
oItem = GetNextItemInInventory(oContainer);
return !(GetIsObjectValid(oItem); # FALSE if a second item was found
}
else # there are zero items
{
return FALSE;
}
return TRUE; # there is exactly one item
}
If you are going for brevity, the following should do the same thing (return TRUE when the container has exactly one item)
// returns TRUE if there the number of items in the container is exactly 1, FALSE otherwise.
int bContainsOne(object oContainer)
{
object oItem = GetFirstItemInInventory(oContainer);
return GetIsObjectValid(oItem) && !(GetIsObjectValid(GetNextItemInInventory(oContainer)) );
}