Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FatalNightmare · Feb 20, 2017 at 02:13 AM · javascriptvariablesenumconstructor

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));
 }
 
 



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FatalNightmare · Feb 20, 2017 at 02:58 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

99 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges