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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by JayCekay · Apr 22, 2013 at 01:12 AM · js to c#

JS Conversion to C# - ToBuiltin? Unity 3 Game Development Hotshot from Jate Wittayabundit

In order to be consistent in the game dev environment, I try to convert JS to C# and have the following problem, apparently with the ToBuiltin function: The original Code in JS from the book:

 public function SaveGame (scores : int, name : String) : void {
     //Submitting the score if the score is higher than the minimum score of the database
     if (scores >= int_minScore) {
         var a_newData : Array = new Array(as_users);
         //Removing the last Array
         a_newData.Pop();
         //Creating new user and save it to array
         var obj_user : UsersData = new UsersData();
         obj_user.Init(name, scores);
         a_newData.Add(obj_user);
         //Setting JS Array back to Builtin
         as_users = a_newData.ToBuiltin(UsersData);
         //Sorting Data
         SortUser(as_users);
     }
     for (var i: int = 0; i < int_maxUser; i++) {
         as_users[i].SaveLocal(i);
     }
 }

Now, my translation:

 public void SaveGame(int scores, string name)
 {
     if(scores >= int_minScore)
     {
         ArrayList a_newData = new ArrayList(as_users);

         a_newData.RemoveAt(int_maxUser - 1);
         
         UsersData obj_user = new UsersData();
         obj_user.Init(name, scores);
         a_newData.Add(obj_user);
         
         as_users = a_newData.ToArray(UsersData);
         SortUser(as_users);
     }
     for( int i = 0; i < int_maxUser; i++)
     {
         as_users[i].SaveLocal(i);    
     }
 }

Can somebody help me with the right conversion? Thank you.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CurtisMcGill · Aug 23, 2013 at 07:26 PM

I haven't fully tested this, but would do something like...

 public class test : MonoBehaviour
 {
     private int int_minScore = 10;
     private int int_maxUser = 10;
     private List<UsersData> as_users = new List<UsersData>();
 
     public void Start()
     {
         // Load list
         UsersData objUser = new UsersData();
         for (int i = 0; i < int_maxUser; i++)
             as_users[i] = objUser.LoadLocal(i);
     }
 
     public void SaveGame(int scores, string name1)
     {
         UsersData objUser = new UsersData();
 
         // Submitting the score if the score is higher than
         // the minimum score of the database
         if (scores >= int_minScore)
         {
             //Removing the last Array
             as_users.RemoveAt(as_users.Count - 1);
 
             //Creating new user and save it to array
             objUser.Init(name1, scores);
             as_users.Add(objUser);
 
             //Sorting Data
             as_users.Sort();
         }
 
         foreach (UsersData usersData in as_users)
             objUser.SaveLocal(usersData);
     }
 }
 
 public class UsersData : MonoBehaviour
 {
     public void Init(string name1, int scores)
     {
     }
 
     public UsersData LoadLocal(int num)
     {
     }
 
     public void SaveLocal(UsersData udata)
     {
     }
 }
 
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

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 Answers

How to import the object from server to unity 2 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