Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ObviouslyInsane · Jan 23, 2012 at 03:10 AM · inventoryexceptionitemout of range

need some help with ArgumentOutOfRangeException

Hi all, my script here is supposed to act as a store where players can buy and sell items.

 Store.js
 
 import System.Collections.Generic;
 
 var x : int;
 var cnt : int;
 
 var Player;
 var InventoryArray;
 var Inventory;
 var gold;
 
 var showGUI = false;
 var showarmorGUI = false;
 var showweaponsGUI = false;
 var showmiscGUI = false;
 
 var storeInventory = new List.<Item>();
 var Items : Items;
 
 var playerInventory;
 
 //private var playerInventory : InventoryList; // reference to the inventory
 
 function Start() {
 
 playerInventory = GameObject.Find("GUIElements").GetComponent("Inventory").inventory;
 for(cnt = 0; cnt < x; cnt++) { 
 storeInventory.Add(Items.StoreInventory1[cnt]); <<<ERROR OCCURS HERE
 }
 }
 
 function OnGUI() {
 if(showGUI == true) {
 
 GUI.Box(Rect(60,60,265,30),"Welcome, stranger. What can I get for you?");
 
 if(GUI.Button(Rect(60,90,60,45),"Armor")){
 showarmorGUI = true;
 }
 
 if(GUI.Button(Rect(60,135,60,45),"Weapons")){
 showweaponsGUI = true;
 }
 
 if(GUI.Button(Rect(60,180,60,45),"Misc")){
 showmiscGUI = true;
 }
 }


 Item.js
 
 enum Rarity{Common, Uncommon, Rare, Beastly, Insane, Epic, Legendary, Null}
 enum ArmorSlots{Head, Neck, Shoulders, Arms, Forearms, Hands, Torso, Waist, Legs, Feet, Null}
 enum JewelrySlots{Ear1, Ear2, Neck, Wrist, Finger1, Finger2, Finger3, Finger4, Finger5, Finger6, Finger7, Finger8, Finger9, Finger10, Null}
 enum WeaponSlot{Primary, Secondary, Ranged, Null}
 enum WeaponSlot2{Primary, Secondary, Ranged, Null}
 
 //var name1 : String;
 
 //var _value : int;
 var name2 : String;
 var description : String;
 var rarity : Rarity;
 var price : int;
 var armorSlot : ArmorSlots;
 var jewelSlot : JewelrySlots;
 var weaponSlot : WeaponSlot;
 var weaponSlot2 : WeaponSlot2;
 var curDura : int;
 var maxDura : int;
 var icon : Texture2D;
 
 function Start() {
 }    
   
 class Item {
 
 function Item(_name2,_description,_rarity,_armorSlot,_weaponSlot,_weaponSlot2,_jewelSlot,_curDura,_maxDura,_icon,_price) {
 
     item_name2 = _name2;
     item_description = _description;
     item_rarity = _rarity;
     item_armorSlot = _armorSlot;
     item_weaponSlot = _weaponSlot;
     item_weaponSlot2 = _weaponSlot2;
     item_jewelSlot = _jewelSlot;
     item_curDura = _curDura;
     item_maxDura = _maxDura;
     item_icon = _icon;
     item_price = _price;
     //item_rarity = Rarity.Rare;
     //item_maxdura = maxDura;
     //item_curdura = curDura;
 
     }
 
 }

 Items.js
 
 import System.Collections.Generic;
 
 var sellList : Item;
 var cnt : int;
 var StoreInventory1 = new List.<Item>();
 
 var my_item : Item; //= new Item("posion",360);
 var my_item1 : Item; //= new Item("posion",360);
 
 function Start() {
 StoreInventory1.Add(my_item);
 StoreInventory1.Add(my_item1);
 }

So as you can see the storeInventory list should be populated with everything contained in the StoreInventory1 list in Items.js However, I am getting an Argument is out of range exception on the line I marked in the Store.js script. Can anyone take a quick look and see what I might be doing wrong? Thank you!

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
2
Best Answer

Answer by Eric5h5 · Jan 23, 2012 at 03:34 AM

What is the "x" variable? It's being set in the inspector, so apparently you have it greater than the length of the StoreInventory1 list. Instead of setting the limit manually like that, just use the count of the list; that way it would be impossible to be out of range.

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 ObviouslyInsane · Jan 23, 2012 at 05:10 AM 0
Share

Thank you Eric, that fixed it!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Creating an inventory/weapon array and ability to scroll through it 1 Answer

Good way to store Items in a mySQL database? 2 Answers

OnTriggerEnter / Inventory question?! 1 Answer

Destroy Item Visuals but store a version of it 2 Answers

MissingReferenceException Help Please! 0 Answers


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