Lemke

Member
Hello guys,trying to do it correctly but getting problems with a code,here is the code:

C#:
private void LinkSpecialItems(Mobile m)
        {
            var boxItems = FindItemsByType(typeof(DonationDyeTub), true);

            if (boxItems != null)
            {
                foreach (var item in boxItems)
                {
                    if (item is DonationDyeTub dt)
                    {
                        if (dt.Owner == null)
                            dt.Owner = m;
                    }

                }
            }
        }
Error im getting is:

C#:
Custom / Donations / Mystery boxes / BaseMysteryBox.cs:
    CS1026: Line 56: Expected)
    CS1002: Line 56: Expected;
    CS1525: Line 56: The term of the expression ')' is not valid
    CS1002: Line 56: Expected;
Scripts: One or more scripts failed to compile or no script files were found.

Any advice?Thank you!!!
 
You need to create a list variable not var
I can't tell from that code snippet exactly what you are trying to do but to create a list you use something like:

Code:
List<Item> list = ((Container)dropped).Items;
    if (list.Count > 0)
    {
        foreach (Item item in boxItems)
            {
                if (item is DonationDytub)
                {
                     DonationDytub dt = (DonationDytub)item;
                    dt.Owner = m;
                }
            }
    }

something like that anyway!
Post automatically merged:

Look at the SalvageBag script also. that has a nice example of manipulating a list of items in a container
 
var is fine, but I am not sure wich line is 56, if I had to guess it would be
Code:
if (item is DonationDyeTub dt)

and that would suggest he is using an older version of C# than the code that is applied there
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back