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 GH0STfdd · Dec 21, 2014 at 02:07 PM · javascriptplayerprefs

Cannot convert int to String

 methas script : 
 var meth : int;
 
     function LoadData()
         {
             var path : String = "C:/Program Files (x86)/moldbsaves/" + methas;
                
            if(File.Exists(path + "/savegame.mbs"))
            {      
                var loadeddata = File.OpenText(path + "/savegame.mbs"); 
                var readdata = loadeddata.ReadLine(); 
                
                while(readdata != null)    
             {                         
                var getdata = readdata.ToString().Split("=" [0]);
                
                if(getdata[0] == "meth")methas.meth = getdata[1]; //here i got error.
                readdata = loadeddata.ReadLine();
             }
                    loadeddata.Close();
            }
         }
     
 
  how i can fix it ?
 
Comment
Add comment · Show 13
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 meat5000 ♦ · Dec 21, 2014 at 01:37 PM 0
Share

Seems like you are trying to store a String in an int container.

avatar image GH0STfdd · Dec 21, 2014 at 02:02 PM 0
Share

so...can i fix this or it's impossible ?

avatar image richyrich · Dec 21, 2014 at 02:10 PM 0
Share

var meth : string;

avatar image GH0STfdd · Dec 21, 2014 at 02:15 PM 0
Share

i tried this but i have another script with many functions where meth is int,i can't just change it to string.

avatar image tanoshimi · Dec 21, 2014 at 02:22 PM 1
Share

"i have another script with many functions where meth is int".

ints and strings are very different things - I can't think of any situation where it wouldn't be obvious which is the correct datatype to use. Just make sure you're consistent.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by WillNode · Dec 21, 2014 at 03:44 PM

try this :

if(getdata[0] == "meth")methas.meth = parseInt(getdata[1]);

the parseInt() function will convert String to int in javascript. but if you want to convert String to int in CSharp, use integer.Parse()

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 GH0STfdd · Dec 21, 2014 at 04:04 PM 0
Share

no errors but when i click load game nothing happened..(

avatar image WillNode · Dec 23, 2014 at 03:06 AM 0
Share

have you check that this line code can be accessed by unity at runtime? try this code again :

 if(getdata[0] == "meth"){
     methas.meth = parseInt(getdata[1]);
     print(getdata[1]);
     }


if this code not appear in unity console, then there is something wrong in your code.

avatar image
0

Answer by Seneral · Dec 21, 2014 at 03:29 PM

http://docs.go-mono.com/?link=M%3aSystem.Int32.Parse(System.String)

 if(getdata[0] == "meth")methas.meth = Int32.Parse(getdata[1]);
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 GH0STfdd · Dec 21, 2014 at 03:31 PM 0
Share

BCE0005: $$anonymous$$ identifier: 'Int32'.

avatar image Bunny83 · Dec 21, 2014 at 03:55 PM 0
Share

@GH0STfdd:
Use int.Parse.

"int" is actually an alias for "System.Int32". Since in Unity you usually don't have a using System; at the top (since it conflicts with some classnames of Unity classes) you would have to type the full class name including the namespace. Since "int" exists there's no need to ever use System.Int32 explicitly

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

How would I transfer these into PlayerPrefs? 0 Answers

Is there a way to clear all the PlayerPrefs with names that start with a specific string? 1 Answer

PlayerPrefs Help 1 Answer

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

Games played script using PlayerPrefabs 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