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 DoctorTodd · Jan 29, 2013 at 12:41 AM · arraybuttons

Problem making buttons from array of array

I'm having some trouble with creating buttons from an array again. This time I'm trying to access the first element of every item in the inventory list. I keep getting multiple errors every way I try it. After eliminating parts to determine the issue it appeared to be [item] in this code below in most cases.

     for (var item in ItemList) { 
     if (GUILayout.Button(ItemList[item][0], GUILayout.Height(wh2 * 0.11))) {
      }
     }  

I also tried this.

     for (var item in ItemList) { 
     if (GUILayout.Button(ItemList[item[0]], GUILayout.Height(wh2 * 0.11))) {
      }
     }  

I did try declaring item as an array but it didn't work. I also tried using the other way of creating buttons from an array but that didn't work either. I tried both of these using the other way. In case you don't know what I'm talking about this is what it looks like.

     for (var item : int = 0; item < ItemList.Length; item++) {
     if (GUILayout.Button(ItemList[item][0], GUILayout.Height(wh2 * 0.11))) {
      }
     }  

Finally I also tried declaring the array two different ways.

 static var ItemList : Array[];
 static var ItemList = new Array();
 

Each way seems to be giving me at least one unique error. I believe I'm going in the right direction by declaring the array the second way.

Comment
Add comment · Show 4
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 whydoidoit · Jan 29, 2013 at 12:42 AM 0
Share

What are the things in ItemList? You should really be using generic collections see this Unity Gems article: http://unitygems.com/gotchas

avatar image DoctorTodd · Jan 29, 2013 at 01:03 AM 0
Share

ItemList contains the arrays for every item in the inventory. Why should I bother using generic collections?

avatar image whydoidoit · Jan 29, 2013 at 09:00 AM 0
Share

Sorry, I meant what is an "item in the inventory"? You should bother because it tells the compiler (and me) what's going on. It gives specific error messages when you do something wrong and its faster.

avatar image DoctorTodd · Jan 29, 2013 at 11:50 PM 0
Share

A series of strings, floats, and integers. I guess I'll take a look at them if it'll increase the speed.

1 Reply

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

Answer by DoctorTodd · Jan 30, 2013 at 05:41 AM

I gave it another shot and this appeared to have fixed it.

     static var ItemList = new Array();
     
     for (var items : Array in Menu.ItemList) { 
     if (GUILayout.Button(items[0], GUILayout.Height(wh2 * 0.11))) {
      }
     } 
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

10 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

Related Questions

Label an array of buttons with an array of strings 2 Answers

[Solved]Using an array of two buttons? 1 Answer

Array out of range! 1 Answer

Change color of all buttons listed in array 3 Answers

Creating Buttons from a Button created from an Array 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