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 eradiuslore · Oct 12, 2011 at 08:35 PM · arraysstringfor-looppragmastrict

ios cant access variables in array

 var arr = new Array()
 var i : int=0;
 var temp : String;
 for(i=0;i<animationSlotsUsed;i++){
     temp = arr[i];
 }

this for some reason dosent work for me, im using pragma strinct so i can compile on ios. any ideas what is wrong?

oh also i cut out the part populating the array with strings

Comment
Add comment · Show 5
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 djmorrsee · Oct 12, 2011 at 09:18 PM 0
Share

What errors or warnings, if any, do you get? It helps if we know what is actually happening. Does it just not assign anything to temp? Are you certain animationSlotUsed isn't 0? Then the loop wont run at all.

avatar image BerggreenDK · Oct 12, 2011 at 09:19 PM 0
Share

also remember ; at the end of EVERY code line. Eg. after Array()

avatar image BerggreenDK · Oct 12, 2011 at 09:20 PM 0
Share

perhaps you could declare the array as type of array too?

var arr : Array = new Array();

avatar image eradiuslore · Oct 12, 2011 at 09:28 PM 0
Share

the error is cant convert type 'object' to 'string' could it be that i have to set the array to type string?

avatar image DaveA · Oct 12, 2011 at 10:15 PM 0
Share

That sounds like it. Otherwise arr is an unknown aka object

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jahroy · Oct 12, 2011 at 11:09 PM

You are trying to use a dynamic (untyped) array.

There are two types of arrays in Unity: dynamic arrays and builtin arrays.

    http://unity3d.com/support/documentation/ScriptReference/Array.html

    I would recommend using a builtin array.

    You can convert a dynamic array to a builtin array like this:

    /* declare dynamic array */

    var dynamicArray = new Array();

    / populate dynamic array with ints /

    for ( var i = 0; i < 10; i ++ ) { dynamicArray.Push(i); }

    / convert to builtin array of known type /

    var builtinIntArray = dynamicArray.ToBuiltin(int);

    Also... unless there is something missing from your code, you never populate the array named arr.

    Your code creates a new, empty, untyped array. It never puts any data in the array (unless there is something you're not showing us).

    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 eradiuslore · Oct 13, 2011 at 01:06 PM 0
    Share

    yes i took out most of the code, it all works well im just transfering scripts over to pragma strict for ios. that looks helpful i will try it out. also do you need to declare the builtin array? to say type string in my case?

    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

    6 People are following this question.

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

    Related Questions

    Assets/Scripts/Enemy.cs(61,44): error CS1955: The member `UnityEngine.GameObject.tag' cannot be used as method or delegate 1 Answer

    [C#]For-loop in For-loop crashes Unity. 1 Answer

    How to split a string into array? 2 Answers

    For loop multiplying the action by the lenght of the array.. WHY ?! 1 Answer

    naming a variable with a number 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