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 e-bonneville · Jul 29, 2010 at 01:58 PM · convertcast

I'm having .ToString Problems

When I try to use .ToString, Unity gives me this error message: Cannot convert 'String' to 'int'. Why?

Here's my code so I don't have to edit it in:

newD1 = newD1.ToString();

Also: I have this line of code that compares the index of this array to a string. The value in the array and the variable are both strings. Yet...

if(monsters[i] == loadEnemyNameToString) {

}

That's giving me this error:

Cannot cast from source type to destination type.

Would you be so kind as to help me again? This problem is giving me eternal frustration.

Oh, and here's what's in the array:

 var monsters = fileContents.Split("-"[0]);

Ah what the heck. Here's the entire function that's such a pain:

function SearchLog () { var sr = new StreamReader(Application.dataPath + "/" + readFilePath); var fileContents = sr.ReadToEnd(); sr.Close();

 var monsters = fileContents.Split("-"[0]);

 for (var i in monsters) {
     if(monsters[i] == loadEnemyName.ToString()) {
         var i2 = i + 1;
         var i3 = i + 2;
         var i4 = i + 3;
         var i5 = i + 4;         

         newEnemyName = monsters[i];
         var loadedEnemyHealth = monsters[i2];
         var loadedEnemyDefense = monsters[i3];
         var loadedD1 = monsters[i4];
         var loadedD2 = monsters [i5];

         newEnemyHealth = float.Parse(loadedEnemyHealth);
         newEnemyDefense = float.Parse(loadedEnemyDefense);
         newD1 = float.Parse(loadedD1);
         newD2 = float.Parse(loadedD2);
     }
 }

}

I'm sure there are much more elegant ways of doing it but I'm on my last bit of juice. At this point I'm just nailing technical looking stuff together.

What I'm doing is loading a file that contains monster attributes. I'm then trying to parse it and split up the file at the - to get an array that contains the name, then the attributes directly after it. What am I doing wrong?

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
2
Best Answer

Answer by 3dDude · Jul 29, 2010 at 02:07 PM

.ToString() returns the value of that value in string format. so if newD1 is not a string then it can't equal a string so your code should look like this:

var newD1String : String;
newD1String = newD1.ToString();

the problem with your code is that your telling it to make newD1 into a string but the only way that would work is if newD1 was a string already.

Comment
Add comment · Show 13 · 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 e-bonneville · Jul 29, 2010 at 02:23 PM 0
Share

Thanks so much. But I have one more question that pertains to the same problem. See my Question above.

avatar image 3dDude · Jul 29, 2010 at 02:25 PM 0
Share

what do you mean? what other problem is there?

avatar image e-bonneville · Jul 29, 2010 at 02:26 PM 0
Share

I just finished editing my Question.

avatar image 3dDude · Jul 29, 2010 at 02:27 PM 0
Share

maybe? :

if(monsters[i] == loadEnemyName.ToString()) {

}

avatar image 3dDude · Jul 29, 2010 at 02:30 PM 0
Share

what is "fileContents"?

Show more comments

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

No one has followed this question yet.

Related Questions

How to cast/convert a ControllerColliderHit into a Prefab 2 Answers

C# Casting Compile Error 1 Answer

casting string as type(for passing to method calling for type)? 1 Answer

how to convert rotation of an object in degrees X 2 Answers

Changing mouse input to touch input... How ? 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