Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by KnightRiderGuy · Dec 28, 2015 at 05:49 PM · c#error messagestringintarduino

Cannot implicitly convert type `string' to `int'

How do I get this:

 // Update is called once per frame
     void Update () {
         /*string dataFromArduinoString = sp.ReadLine ();
         int dFAI = int.Parse (dataFromArduinoString);
         print (dFAI);
         DirectionArrow (dFAI);*/
 
         try
         {
             //DirectionArrow(sp.ReadByte());
             //print(sp.ReadByte());
             string dataFromArduinoString = sp.ReadLine ();
             int dFAI = int.Parse (dataFromArduinoString);
             print (dFAI);
             DirectionArrow (dFAI);
         }
         catch (System.Exception) {
 
         }



to work with this:

 void DirectionArrow(int buttonStatus)
     {
         
     switch (buttonStatus)
     {
         //OFF Buttons  States
         //case 0:
         case "O":
             //deactivate Left Direction Arrow
             SystemGuidanceManagerScript WAOff = FindObjectOfType<SystemGuidanceManagerScript>();
             WAOff.WestArrowOff ();
 
             SystemGuidanceManagerScript EAOff = FindObjectOfType<SystemGuidanceManagerScript>();
             EAOff.EastArrowOff();
 
             SystemGuidanceManagerScript SFXOff = FindObjectOfType<SystemGuidanceManagerScript>();
             SFXOff.TopIndicatorOff();
 
             SystemGuidanceManagerScript BGSOff = FindObjectOfType<SystemGuidanceManagerScript>();
             BGSOff.BarLEDsSounderOff();
             break;
         //LEFT BUTTON ON STATE
         //case 1:
         case "W":
             //Activate Left Direction Arrow Indicator
             SystemGuidanceManagerScript WAOn = FindObjectOfType<SystemGuidanceManagerScript>();
             WAOn.WestArrow();
 
             SystemGuidanceManagerScript WBSOn = FindObjectOfType<SystemGuidanceManagerScript>();
             WBSOn.BarLEDsSounderOn();
             break;
         //RIGHT BUTTON ON STATE
         //case 2:
         case "E":
             //Activate Right Direction Arrow Indicator
             SystemGuidanceManagerScript EAOn = FindObjectOfType<SystemGuidanceManagerScript> ();
             EAOn.EastArrow ();
 
             SystemGuidanceManagerScript EBSOn = FindObjectOfType<SystemGuidanceManagerScript>();
             EBSOn.BarLEDsSounderOn();
             break;
     }
             
     }


Comment
Add comment · Show 2
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 SoloDeveloper · Dec 29, 2015 at 03:57 AM 0
Share

Try changing print (dFAI); to print (" " + dFAI);

avatar image KnightRiderGuy SoloDeveloper · Dec 29, 2015 at 01:48 PM 0
Share

@SoloDeveloper, Thanks I tried that, and It gave me an error, I found out from another post where I worded the question a bit differently that I needed to do this in my Update:

 void Update () {
         try
         {
             string message3 = sp.ReadLine(); //get the message...
             if(message3 == "") return; //if its empty stop right here
             print(message3);
             DirectionArrow (message3.Trim());
 
         }
         catch (System.Exception ex) {
             print (ex.$$anonymous$$essage);
             return;
         }
             //print("BytesToRead" +sp.BytesToRead);
             message2 = sp.ReadLine();
             
         string message = sp.ReadLine(); //get the message...
         if(message == "") return; //if its empty stop right here
         // parse the input to a float and normalize it (range 0..1) (we could do this already in the Arduino)
 
         float input =  1 -  float.Parse (message) / 100f;
         // set the slider to the value
         float oldValue = slider.value; // -------- this is new
         slider.value = input;
 
         // after the slider is updated, we can check for the other things for example play sounds:
 
         if (source.isPlaying) return; // if we are playing a sound stop here
 
         // else check if we need to play a sound and do it
         if (slider.value > 0.9f && oldValue <= 0.9f) // ---------this has changed
             source.PlayOneShot (BrightnessAudioClips [Random.Range (0, BrightnessAudioClips.Length)]);
 
         else if (slider.value < 0.15f && oldValue >= 0.15f) //----------this has changed
             source.PlayOneShot (DarknessAudioClips [Random.Range (0, DarknessAudioClips.Length)]);
         
 
     }


And this in my Switch Statement:

 void DirectionArrow(string buttonStatus)
     {
         
         switch (buttonStatus)
     {
         //OFF Buttons  States
         case "O":
             //deactivate Left Direction Arrow
             SystemGuidance$$anonymous$$anagerScript WAOff = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript>();
             WAOff.WestArrowOff ();
 
             SystemGuidance$$anonymous$$anagerScript EAOff = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript>();
             EAOff.EastArrowOff();
 
             SystemGuidance$$anonymous$$anagerScript SFXOff = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript>();
             SFXOff.TopIndicatorOff();
 
             SystemGuidance$$anonymous$$anagerScript BGSOff = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript>();
             BGSOff.BarLEDsSounderOff();
             break;
         //LEFT BUTTON ON STATE
         case "W":
             //Activate Left Direction Arrow Indicator
             SystemGuidance$$anonymous$$anagerScript WAOn = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript>();
             WAOn.WestArrow();
 
             SystemGuidance$$anonymous$$anagerScript WBSOn = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript>();
             WBSOn.BarLEDsSounderOn();
             break;
         //RIGHT BUTTON ON STATE
         case "E":
             //Activate Right Direction Arrow Indicator
             SystemGuidance$$anonymous$$anagerScript EAOn = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript> ();
             EAOn.EastArrow ();
 
             SystemGuidance$$anonymous$$anagerScript EBSOn = FindObjectOfType<SystemGuidance$$anonymous$$anagerScript>();
             EBSOn.BarLEDsSounderOn();
             break;
     }
             
     }

0 Replies

· Add your reply
  • Sort: 

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

49 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Error FormatException: Input string was not in a correct format. 0 Answers

Having trouble converting this int to string, can someone help? 0 Answers

Accesing specific int from inspector 2 Answers

trying to get an Array string to read an Int 0 Answers

Word guessing game 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