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
1
Question by Anxo · Apr 16, 2014 at 08:33 PM · c#ienumeratorreturn value

Pass Variable to public Variable for processing?

I thought I used to do things like this all the time but I am either having an off day or dreaming about features that I never used?

Anway, what I am trying to do is very simple. I often do this.

 private string variableA = "";
 
 variableA = variableB;
 
 public varibaleB { 
    get{
          return "Answer!";
 }
 } 
 
 // which works well right? I also often do this. 
 private string variableA = "";
 CalculateVariableB();
 
 public void CalculateVariableB (int numberA, int numberB){
   if(numberA>numberB)
 variableA = "YES";
 else
 variableA = "NO";
 }
 
 
 // Works well right? Now here is where the problem comes in, I wish to do this.
 
 private string variableA = "";
 
 variableA = variableB(1,5);
 
 public string variableB(int numberA, int numberB){  //Edit:  <--- This is where the problem is, while this looks good, this line does not work as I can not pass the variables into the string. 
     if(variableA > variableB)
          return "YES";
  else
        return "NO";
 }

I think when I used to write in Javascript it was something like

 function VariableB(numberA : int, numberB : int) : string{
     // do something and return a string?
 
 }

But I am not sure I remember correctly or how to pull it off in C#.

Thanks guys.

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

2 Replies

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

Answer by fendorio · Apr 16, 2014 at 08:54 PM

     public string x { get { return Foo(1, 2); } }

     private static string Foo(int x, int y)
     {
         return (x > y) ? "Bigger" : "Smaller";
     }

What you're looking for?

    Debug.Log(x) 

Would result in : "Smaller" in this case.

Yeah as the answer states below you're bug was that you weren't testing the two method parameters namely numberA & numberB

  public string variableB(int numberA, int numberB)
  {  
      if(variableA > variableB) //Should be (numberA > numberB)
          return "YES";
      else
          return "NO";
  }
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 Anxo · Apr 16, 2014 at 09:43 PM 0
Share

lol, Thumbs up to you both. I did a horrible job trying to explain my problem but b/c you guys gave me back my answer without actually seeing my problem, I realized what I did wrong. Yes I was checking the variable vs the variable ins$$anonymous$$d of the number which was a mistake in my example by what my real problem was that I was doing this.

 public string $$anonymous$$yString (string inco$$anonymous$$gString){
      get{
          return "some string";
      }
 }
 
 // Ins$$anonymous$$d of 
 
 public string $$anonymous$$yString(string inco$$anonymous$$gString){
      return "some string";
 }

Thats what my problem was and I have been tippytowing around it for 2 days by doing this.

 public string returnString ="";
 
 public string $$anonymous$$yString {
 get{
      // do something with return string and return a string
 return "some string";
 }
 
 }


which was a really annoying workaround. Anyway. Thanks for helping me see the light guys.

avatar image fendorio · Apr 16, 2014 at 09:45 PM 0
Share

Glad to be of service! It's always the 'obvious' bugs which are hardest to find! Btw I've just been doing some math stuff with the console so only made the above Foo static out of habit lol. Hope the project goes well :)

avatar image
1

Answer by MFen · Apr 16, 2014 at 08:57 PM

 public string variableB(int numberA, int numberB){  //Edit:  <--- This is where the problem is, while this looks good, this line does not work as I can not pass the variables into the string. 
     if(variableA > variableB)
          return "YES";
  else
        return "NO";
 }

change it to this

 public string variableB(int numberA, int numberB){  //Edit:  <--- This is where the problem is, while this looks good, this line does not work as I can not pass the variables into the string. 
     if(numberA> numberB)
          return "YES";
  else
        return "NO";
 }
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

22 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Make a laser flickering. 1 Answer

Yield Wait for Seconds (A little help here) 2 Answers

Triggers and SendMessages. C# 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