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 /
  • Help Room /
avatar image
1
Question by Semut · Apr 14, 2011 at 11:22 AM · conversionsyntax-errorcs0266

Conversion From Unity JS to C# - Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?)

I'm trying to convert Unity JS

function LoadLastSavedSelection() { var strIDs : String[] = EditorPrefs.GetString("SelectedIDs").Split(char.Parse(";"));

 var ids : int[] = new int[strIDs.Length];
 for(var i = 0; i < strIDs.Length; i++)
 ids[i] = parseInt(strIDs[i]);
 Selection.instanceIDs = ids;

}

into C#. And below my last converted that still have some errors.

void LoadLastSavedSelection (){ string[] strIDs = EditorPrefs.GetString("SelectedIDs").Split(char.Parse(";"));

     int[] ids = new int[strIDs.Length];
     for(float i = 0; i < strIDs.Length; i++)
     ids[i] = int.Parse(strIDs[i]);
     Selection.instanceIDs = ids;
 }

Errors code that I get

(308,43): error CS0266: Cannot implicitly convert type float' toint'. An explicit conversion exists (are you missing a cast?)

(308,21): error CS0266: Cannot implicitly convert type float' toint'. An explicit conversion exists (are you missing a cast?)

Line 308 is

        ids[i] = int.Parse(strIDs[i]);

Can anyone help me solve the conversion so I don't have some errors. Thank in advance!

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

2 Replies

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

Answer by Wibbs 1 · Apr 14, 2011 at 11:30 AM

its because i is declared as a float in the for loop. Array indexes need to be integers, so the line should read:

for(int i = 0; i < strIDs.Length; i++)
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 Semut · Apr 14, 2011 at 11:36 AM 0
Share

Yes, my fault! I have some floats o other code before that make me forget about 'culprit' float at current code. Great help, Thank!

avatar image
1

Answer by robertmathew · Apr 14, 2011 at 11:43 AM

http://www.m2h.nl/files/js_to_c.php

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 Semut · Apr 14, 2011 at 02:47 PM 0
Share

Thanks for the great resources.

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

1 Person is following this question.

avatar image

Related Questions

problem with dff importer script 1 Answer

2D minimap - convert click point to world point 0 Answers

Java to C# Translation 1 Answer

How to make a character controller through another script 0 Answers

Change a primative list type to a class list type 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