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 /
avatar image
0
Question by Mulldor · Jul 05, 2017 at 03:43 PM · functionreturn valuehighest

Choosing function with highest return value

Is there a way for me to create a function which activates the highest return value?

Example:

 public void ChooseFunction()
 {
  //Choose function2, as it has the highest returning value
 }
 
 float Function1 ()
 {
  return 1;
 }
 float Function2 ()
 {
  return 2;
 }

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

Answer by SolomonG · Jul 05, 2017 at 05:15 PM

Just to clarify, do you want ChooseFunction() to return the highest value returned between Function1() and Function2(), or do you only want the function that would return the highest value to be called, and not the other?

Comment
Add comment · Show 6 · 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 Mulldor · Jul 05, 2017 at 06:08 PM 0
Share

I want the function that would return the highest value to be called and not the other

avatar image SolomonG Mulldor · Jul 05, 2017 at 06:42 PM 0
Share

That's more difficult then. I'm guessing that the functions will be modifying and accessing variables outside of method scope (i.e. not stateless), so you can't just run them normally to evaluate. I'd maybe add an argument bool evalRun and modify the functions so that if evalRun == true, the functions won't modify anything outside of method scope. However, depending on the function purpose, that might not be possible. What will the functions be doing?

avatar image Mulldor SolomonG · Jul 05, 2017 at 06:53 PM 0
Share

Each function will correspond to a utility in an AI.

For example, the need to flee if low hp.

What I need to do is find a way to import these into something like an array - and then evaluate the highest utility need.

Perhaps a way to do it is to make all functions return an array with the utility weight (amount) and their name.

After that I loop through the first level of the array to find highest returned value - when found I then take the 2nd level of the array and use .Sendmessage --- $$anonymous$$aybe this would work?

Show more comments
avatar image
0

Answer by efeguclu · Jul 05, 2017 at 07:56 PM

Can use this :

  float highest = ((Function1() > Function2()) ? Function1() : Function2());


Or if you want to call the function you can use something like :

  public void ChooseFunction()
  {
   //Choose function2, as it has the highest returning value
 bool oneisbigger = (Function1() > Function2())
 
 if(oneisbigger)
 Function1();
 else
 Function2();
  }
  
  float Function1 ()
  {
   return 1;
  }
  float Function2 ()
  {
   return 2;
  }
 void Function1(){
 
 }
 void Function2(){
 
 }
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

69 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 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

Not all code paths return a value 1 Answer

return value of a function passed to another function as a parameter 0 Answers

Function cannot return int!? 2 Answers

How to return a Vector3 value? 2 Answers

Making a script's functions available with 'using...' 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