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 skoandi · Nov 26, 2012 at 10:45 PM · c#javascripttranslateleaderboard

Can someone translate this to Javascript?

I'm making a leaderbord (http://forum.unity3d.com/threads/134939-Free-easy-to-implement-LeaderBoard)

I know Javascript really good but I can't translate this part:

string[] rows = this.highScores.Split(new char[] {'\n'}, System.StringSplitOptions.RemoveEmptyEntries); foreach (string r in rows) { string[] values = r.Split(new char[] {'|'}, System.StringSplitOptions.RemoveEmptyEntries); GUILayout.BeginHorizontal(); GUILayout.Label(values[0], width200); GUILayout.Label(values[1], width200); GUILayout.EndHorizontal(); }

Thanks!

Comment
Add comment · Show 3
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 AlucardJay · Nov 27, 2012 at 06:51 AM 0
Share

for any help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

Though, it may be easier just to delete the code, paste it in again from the source, then highlight all the code and press the 101010 button at the top of the edit window before posting.

avatar image AlucardJay · Nov 27, 2012 at 06:52 AM 0
Share

I found these links useful for converting between C# and JS :

http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

avatar image skoandi · Nov 27, 2012 at 09:44 AM 0
Share

Thanks! btw I forced myself to make the leaderboard in C# now xd

1 Reply

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

Answer by dukearena · Nov 27, 2012 at 11:01 AM

C# syntax and Javascript syntax are different in some points, especially in variables declaretion.. This is the translation:

 var rows : string[] = highScores.Split('n', System.StringSplitOptions.RemoveEmptyEntries);
 
 for(var i = 0; i<rows.length; i++) {
    var r : string = rows[i];
    var values : string[] = r.Split('|', System.StringSplitOptions.RemoveEmptyEntries);
    GUILayout.BeginHorizontal();
    GUILayout.Label(values[0], width200);
    GUILayout.Label(values[1], width200);
    GUILayout.EndHorizontal();
 }

I haven't tried it in Unity but it should work :D

I explain the differences:

1 - Javascript doesn't have a foreach.. There are many methods for build it but it's more simple to use the simple for statement.

2 - Javascript have a long declaration.. It needs "var varname : type", C# only "type varname"

Please, let me know if I've written some errors :D

Comment
Add comment · Show 2 · 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 skoandi · Nov 29, 2012 at 08:14 AM 0
Share

Wow thank you so much! :D I'll try it out when I get home :)

avatar image dukearena · Nov 29, 2012 at 09:42 AM 0
Share

Don't forget to vote up if works :D

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

12 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

Related Questions

Translate Unity-scripts to uScript 1 Answer

java to C# conversion 1 Answer

Camera Effect + Translating US to C# 3 Answers

translate C# with => to unityscript 2 Answers

Converting Variable to C# 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