Compilation Errors for Database Scripts

I’m trying to make an item database so I followed an online guide however, the scripts outlined in the guide have compilation errors. Any help would be appreciated, I’m a beginner in both Unity and C# so please make the explanations simple. The errors indicated in unity are as follows:

  1. item.cs
    “There are inconsistent line endings in the ‘Assets/Inventory/Scripts/item.cs’ script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.” -I tried converting the line endings but the error remained.
using UnityEngine;

[CreateAssetMenu(fileName = "New Item", menuName = "Assets/Item")]
public class Item : ScriptableObject
{
    public string itemID;
    public string itemName;
    [TextArea]
    public string itemDescription;
    public int itemCost;
    public Sprite itemSprite;
}
  1. ItemDataBase.cs
    “There are inconsistent line endings in the ‘Assets/Inventory/Scripts/ItemDataBase.cs’ script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "New Item Database" , menuName = "Assets/Databases/Item Database")]
public class ItemDatabase : ScriptableObject
{
    public List<Item> allItems;
}

3.DataBase.cs
“Assets\Inventory\Scripts\Database.cs(30,40): error CS0119: ‘Database.GetRandomItem()’ is a method, which is not valid in the given context”
"Assets\Inventory\Scripts\Database.cs(30,40): error CS0119: ‘Database.GetRandomItem()’ is a method, which is not valid in the given context

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class Database : MonoBehaviour
{
    public ItemDatabase items;
    private static Database instance;

    private void Awake()
    {
        if(instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    public static Item GetItemByID(string ID)
    {
        return instance.items.allItems.FirstOrDefault(i => i.itemID == ID);
    }
    public static Item GetRandomItem()
    {
        return instance.items.allItems[GetRandomItem.Range(0, instance.items.allItems.count())];
    }


}

"

Inconsistent line endings is just a warning. It’s also pretty self explanatory. I won’t elaborate further.

I think you meant Random.Range probably instead of GetRandomItem.Range?

Also count() is incorrect. It’s just a property and it’s Count, capitalized and no parentheses.

1 Like

Thank you for the help, the comp errors are resolved now.