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 Grimmy · Dec 31, 2010 at 11:20 AM · returngenerator

What is the meaning of Generators cannot return values?

I'm unlear of why a certain functions are not able to return a value. eg

var x:String;

x=ReturnSomething();

function ReturnSomething() { if(somethingDifferentHappened) { return("Something different"); } return("Something ordinary"); }

are these 'nested' returns the root of the problem?

Comment
Add comment · Show 1
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 Fattie · Sep 08, 2012 at 02:41 PM 0
Share

try this

 function ReturnSomething():String

etc.

1 Reply

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

Answer by Mike 3 · Dec 31, 2010 at 11:28 AM

Usually it'll be because your function has a yield in it, which turns the function into a generator.

The compiler turns those functions into a pretty blank function which creates and returns an instance of a class, which has the code from your original function inside it.

Because the function has to return that class, it can't return whatever you're trying to return yourself.

Comment
Add comment · Show 3 · 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 Grimmy · Dec 31, 2010 at 11:32 AM 0
Share

Gotcha..my above example probably actually works, but the one in my game does indeed have a yield in it. I can pretty much understand this because of course the var which calls the fuction would never actually recieve anything back until the functions yield had completed.

avatar image goo-muffin · Sep 08, 2012 at 02:33 PM 0
Share

but how can I solve this problem?

avatar image Fattie · Sep 08, 2012 at 02:44 PM 0
Share

you can't solve the problem that you can't return a value from a coroutine.

indeed conceptually .......... you can't solve the problem "what the hell do I do while some other thingy is running ?"

just code around it .. typically with a callback

so have a new routine called something like ThatOtherDamnThingHasFinallyFinished

at the end of your quasi-thread you must call to that routine.

that's life !

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I return a reference to an object downloaded via a function? 0 Answers

how do i generate cubes to form a sphere? 4 Answers

Random box generator in certain area. 1 Answer

Null reference for variables(prefabs) when referencing another script 0 Answers

Returning byte array from Java/Android 3 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