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 imagoculturae · Nov 22, 2017 at 07:54 PM · lists

Fill Lists recursevely

Hi all, I am trying to map elements of a list into another list. I have succeed doing it manually(see the commented part) but I really want to do it recursively. Can someone tell me how to do it?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using MidiJack;
 using UnityEngine.UI;
 
 public class MidiControlMapping : MonoBehaviour {
     
     //public int[] knobNumber; 
     public  List <int> myknobs;
     public  List <Slider> mysliders;/
 
 //public Slider mySlider;
 
 
     void Start()
     {
         //sliders = new List<Slider>();
     }
 
 
     void Update()
     {
 
         SetSlider ();
     }
 
 
 public void SetSlider()
 {
         
 
 
         foreach(int i in myknobs)
         { 
             
             mysliders[i].value =  MidiMaster.GetKnob(myknobs[i]);
 
         }
         //mysliders[0].value =  MidiMaster.GetKnob(knobNumber[0]);
         //mysliders[1].value =  MidiMaster.GetKnob(knobNumber[1]);
         //mysliders[2].value =  MidiMaster.GetKnob(knobNumber[2]);
       //Debug.Log("You are using knob number = " + knobNumber);
 }
 }
Comment
Add comment · Show 12
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 Hellium · Nov 22, 2017 at 08:54 PM 0
Share

What problem are you facing? Have you any error in the console?

avatar image imagoculturae · Dec 12, 2017 at 02:44 PM 0
Share

I get: ArgumentOutOfRangeException: Argument is out of range.

In short how do I assign the first element of a list to the first element of a second list, the second element of of the first list with the second element of the second list and so on...but recursively?

avatar image Hellium imagoculturae · Dec 12, 2017 at 04:04 PM 0
Share

I'm not sure you understand what "recursively" means.

Here, your problem has nothing with recursion. Your mySliders list is simply not big enough for all your knobs.

You may want to do :

 private List <Slider> mysliders;
 public void SetSlider()
 {
      mysliders = new List<Slider>();
      foreach(int i in myknobs)
      {              
          mysliders.Add( $$anonymous$$idi$$anonymous$$aster.Get$$anonymous$$nob(myknobs[i]) ) ; 
      }
  }
avatar image imagoculturae · Dec 12, 2017 at 10:01 PM 0
Share

Ok but now I have:

 Assets/Scripts/$$anonymous$$idiControl$$anonymous$$apping.cs(44,14): error CS1502: The best overloaded method match for `System.Collections.Generic.List.Add(UnityEngine.UI.Slider)' has some invalid arguments

and

 Assets/Scripts/$$anonymous$$idiControl$$anonymous$$apping.cs(44,30): error CS1503: Argument `#1' cannot convert `float' expression to type `UnityEngine.UI.Slider'

mySliders and myknobs need to be public because I need to add them in the editor.

I thought recursively meant when you don't do it manually but usually with a for loop, if not I am sorry I am not a programmer

avatar image Hellium imagoculturae · Dec 12, 2017 at 10:28 PM 0
Share

You have to change the type between the <> symbols so as to match the type returned by $$anonymous$$idi$$anonymous$$aster.Get$$anonymous$$nob

Recursion in program$$anonymous$$g means an other things check the wikipedia page or this link which is simpler.

avatar image imagoculturae · Dec 12, 2017 at 10:38 PM 0
Share

Yeah of course sorry I meant iteration not recursion... anyway now it works...sort of, no error but the numbers of sliders all ways stays at 0

avatar image Hellium imagoculturae · Dec 12, 2017 at 10:42 PM 0
Share

$$anonymous$$ake sure the myknobs list is not empty and $$anonymous$$idi$$anonymous$$aster.Get$$anonymous$$nob returns elements correctly.

avatar image imagoculturae · Dec 12, 2017 at 10:53 PM 0
Share

alt text

As You can see I have re-filled the list in the editor, but now it went back to the original error

knobs.jpg (40.7 kB)
avatar image Hellium imagoculturae · Dec 12, 2017 at 10:55 PM 0
Share

If you do it through the inspector, you don't need to call SetSlider by code anymore.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

120 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 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

Store instantiated object in List 2 Answers

Creating card game - copy of list to new list - creating cycle 1 Answer

Trying to get gameobject from one list to follow gameobjects in another list 1 Answer

Filter list items and display them 1 Answer

How get a count of Lists assigned 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