- Home /
Making a List for Inventory System, Got an error in finding constructors and variables
Hello everyone, I am currently following tutorials on making an Inventory system for my game. Right now I have a code for my Item (IS_ItemHandler) and an Inventory Management code (IS_Items). I made a public class in ItemHandler with variables and an itemsList in Items calling those variables.
I have copied the tutorials exactly, but it is 2 years old. So did a Unity update cause this error? I am teaching myself Javascript and still heavily an amateur. Sorry if my coding vocab is off.
I am getting this error: Assets/My Assets/Javascript/IS_Items.js(19,34): BCE0024: The type 'ItemHandler' does not have a visible constructor that matches the argument list '(int, UnityEngine.Texture2D, String, String, boolean, ItemType, Rarity)'.
Let me know if you need for details. Thank you!
Here are both of my codes:
IS_ItemHandler -
public class ItemHandler
{
var itemID : int;
var icon : Texture2D;
var name : String;
var description : String;
var equipped : boolean = false;
var itemType : ItemType;
var rare : Rarity;
}
function ItemHandler(ID : int, ItemIcon : Texture2D, ItemName : String, ItemDescription : String, Equipped : boolean, Type : ItemType, Rareness : Rarity)
{
this.itemID = ID;
this.icon = ItemIcon;
this.name = ItemName;
this.description = ItemDescription;
this.equipped = Equipped;
this.itemType = Type;
this.rare = Rareness;
}
enum ItemType
{
Battery,
Health,
Door,
Leftarm,
Rightarm,
Leftleg,
Rightleg,
Brain,
TwoHands,
OneHand
};
enum Rarity
{
Verycommon,
common,
uncommon,
lore,
rare,
veryrare,
extremerare,
prime
};
IS_Items
import System.Collections.Generic;
var itemsList : List.<ItemHandler> = new List.<ItemHandler>();
private var item1Icon : Texture2D;
private var item2Icon : Texture2D;
private var item3Icon : Texture2D;
function Start ()
{
//Icons Items Start
item1Icon = Resources.Load("Items/Item1", Texture2D);
item2Icon = Resources.Load("Items/Item2", Texture2D);
item3Icon = Resources.Load("Items/Item3", Texture2D);
//Icons Items End
//Items Start
//ID int, Icon Texture, Name String, Desc. String, Equip Boolean, Type ItemType, rarityList Rarity
//0
itemsList.Add(ItemHandler(1, item1Icon, "Battery", "Battery's Mock Description.", false, ItemType.Battery, Rarity.Verycommon));
}
Answer by $$anonymous$$ · Feb 20, 2017 at 02:46 AM
Try putting the function ItemHandler (...){...} inside of the ItemHandler class like so:
public class ItemHandler
{
var itemID : int;
var icon : Texture2D;
var name : String;
var description : String;
var equipped : boolean = false;
var itemType : ItemType;
var rare : Rarity;
function ItemHandler(ID : int, ItemIcon : Texture2D, ItemName : String, ItemDescription : String, Equipped : boolean, Type : ItemType, Rareness : Rarity)
{
this.itemID = ID;
this.icon = ItemIcon;
this.name = ItemName;
this.description = ItemDescription;
this.equipped = Equipped;
this.itemType = Type;
this.rare = Rareness;
}
}
I'm not 100% sure if this will fix it, as I haven't programmed with JS in Unity for a while. I know for C# though, it must be inside of the actual class.
Thank you! Yes, this was the fix. So darn simple like always... I did exactly that, I put the function inside the public class.
Your answer
Follow this Question
Related Questions
Construct class with enum parameter (javascript) 0 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
EnumStates 1 Answer
Changing a variable on a different object 2 Answers
Activate line just one time 1 Answer