Dispenser.GetContents
Skip to content
mnscript
DispenserItem[] Dispenser.GetContents() 

Description ​

Gets contents of the dispenser.

Returns ​

DispenserItem[] - An array of DispenserItem.

Example ​

msc
using Peripheral;
using Console;
using Application;
using Util;
using Array;

Dispenser dispenser = Peripheral.GetConnectedDispenser();

if(dispenser.IsValid() == false){
    // If the dispenser was not found, quit.
    Application.Exit();
}

// Searches for items in the dispenser.
DispenserItem[] items = dispenser.GetContents();

number numItems = Array.Length(items);
Console.WriteLine("");
Console.WriteLine("Dispenser unique items: "..Util.ToString(numItems));

// Print each item in the console
number i = 1;
while(i <= numItems){
    DispenserItem item = items[i];

    Console.WriteLine("Item: "..item.GetName().." Amount: "..Util.ToString(item.GetAmount()));

    i = i + 1;
}