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 /
  • Help Room /
avatar image
0
Question by BeefEX · Dec 14, 2015 at 01:26 PM · unity 5

Dictionary

Hi, i am making Inventory system using Dictonaries. When i write my Dictionary definition it is allright, but when i write anything after it, even space, it says "The name "Dictionary" does not exist in current context". I have imported System.Collections.Generic and rest of script is fine. Any idea? Thanks

EDIT: CODE (it is on the very end of it)

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class InventoryClass {
 
 }
 
 public class Inventory {
     Slot[] inventory;
     
     public Inventory () {
         inventory = new Slot[20];
         createInventory ();
     }
     
     public Inventory (int SlotCount) {
         inventory = new Slot[SlotCount];
         createInventory ();
     }
 
     public Slot[] Inventory2 {
         get {
             return inventory;
         }
     }
 
     void createInventory () {
         for (int slotI = 0; slotI < inventory.Length; slotI++) {
             inventory[slotI] = new Slot(Item.ItemTypes.Stone);
         }
     }
 }
 
 public class Slot {
     
     public enum ChangeItemCountMode {Add, Remove, Set};
     
     int contentCount;
     Item content;
     
     public Slot () {
         content = new Item(Item.ItemTypes.Empty);
         contentCount = 0;
     }
     
     public Slot (Item.ItemTypes itemtype) {
         content = new Item(itemtype);
         contentCount = 1;
     }
     
     public Slot (Item.ItemTypes itemtype, int itemcount) {
         content.ChangeItemType(itemtype);
         contentCount = itemcount;
     }
     
     public void ChangeItemCount (ChangeItemCountMode mode, int number) {
         int oldCount = contentCount;
         if (mode == ChangeItemCountMode.Add) {
             contentCount += number;
         } else if (mode == ChangeItemCountMode.Remove) {
             contentCount -= number;
         } else if (mode == ChangeItemCountMode.Set) {
             contentCount = number;
         }
         content.OnItemCountChanged (oldCount, contentCount);
     }
 
     public Item Content {
         get {
             return content;
         }
     }
 
 }
 
 public class Item {
     public enum ItemTypes {Empty, Dirt, Stone};
     
     ItemTypes itemtype;
     
     public Item () {
         itemtype = ItemTypes.Empty; 
     }
     
     public Item (ItemTypes itemtype_) {
         itemtype = itemtype_;
     }
     
     public void ChangeItemType (ItemTypes itemtype_) {
         itemtype = itemtype_;
     }
     
     public ItemTypes Itemtype {
         get {
             return itemtype;
         }
     }
 
     //Dummy method to override.
     public virtual void OnItemCountChanged (int prevCount, int newCount) {
         
     }
 }
 
 public class ItemList {
     Dictionary<int, string, Sprite> itemDic = new Dictionary<int, string, Sprite>();
 }

Comment
Add comment · Show 1
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 Dave-Carlile · Dec 14, 2015 at 01:26 PM 0
Share

Lots of ideas, but none of them are useful unless we can see your code.

1 Reply

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

Answer by Dave-Carlile · Dec 14, 2015 at 01:59 PM

A Dictionary is effectively a key/value store. A key can be associated with a single value. When declaring the dictionary the key type and the value type are specified. You're trying to define 3 types.

Probably what you want is string or int for the key, and a class type for the values.

 class MyDictionaryItem
 {
    public int SomeValue;
     public string SomeOtherValue;
 }


 Dictionary<string, MyDictionaryItem> items = new Dictionary<string, MyDictionaryItem>();


You look the MyDictionaryItem items up by a string key (or int if you change it to that). Then you have access to the individual MyDictionaryItem class properties.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UNET Spawning armor 1 Answer

How can i solve the spikes on my empty project ? 0 Answers

Question about NavMesh and Rigidbody 0 Answers

How do GameObjects detect void Update and how to make my custom one. 0 Answers

Unity 2D game trigger event by game start 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