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 killerstreak · Aug 27, 2014 at 04:02 PM · functionreturn

return doesnt return a value.

newbee here with a question

So I call this function from another script using sendmessage and inject a value named time. time is used to calculate the speed. Speed is used in the same script. However function movebar never seems to return speed. Debug.log shows me that speed is = 1 for instance, but outside the function it remains 0.

what am I doing wrong.

  var speed : float;
 
 function movebar (time :float) : float
 {
 var speed :float = 0; 
 speed = 1 / time;
 Debug.Log(speed);
 Debug.Log(time);
 return speed;
 }

 function Update () {
 var step = speed * Time.deltaTime;
 loadingbar.position = Vector3.MoveTowards(bar.position, bartarget.position,step);
 }




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 vptb · Aug 27, 2014 at 04:16 PM 0
Share

This is really confusing, so tell me if you're calling that function with sendmessage, why do you want a return method? Send$$anonymous$$essage doesn't return anything...

Please tell us what exactly you want to do with it, so we can offer you a solution.

avatar image killerstreak · Aug 27, 2014 at 04:27 PM 0
Share

some more explanation here: I got 2 scripts A and B. in script A Sendmessage refers to the function movebar in script B and sends a variable called time with it.

the $$anonymous$$ovebar function In script B takes time and uses it to change the speed variable. wich needs to be returned and used later on in script B.

however the speed variable never changes.

2 Replies

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

Answer by Eric5h5 · Aug 27, 2014 at 04:35 PM

The global "speed" variable is entirely different from the local "speed" variable inside the function. SendMessage can't return any value...hint: **Send**Message. It's one-way only. If the function is supposed to change the global "speed" variable, then it should use that rather than declaring a new local variable.

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

Answer by Landern · Aug 27, 2014 at 04:03 PM

Where is your return type from the function/method?

 var speed : float;
  
 function movebar (time :float) : float {
     var speed :float = 0; 
     speed = 1 / time;
     Debug.Log(speed);
     Debug.Log(time);
     return speed;
 }
  
 function Update () {
     var step = speed * Time.deltaTime;
     loadingbar.position = Vector3.MoveTowards(bar.position, bartarget.position,step);
 }
Comment
Add comment · Show 4 · 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 killerstreak · Aug 27, 2014 at 04:08 PM 0
Share

I added float as the return type of the function. Nothing changes however its still not working.

avatar image Landern · Aug 27, 2014 at 04:09 PM 0
Share

what is calling movebar? is it from Send$$anonymous$$essage?

avatar image killerstreak · Aug 27, 2014 at 04:28 PM 0
Share

yes movebar is being called from a different script by Send$$anonymous$$essage

avatar image Landern · Aug 27, 2014 at 04:30 PM 0
Share

Send$$anonymous$$essage doesn't allow a return of a value. It's void for obvious reasons.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

C# Function that returns instantiated object 1 Answer

type function not returning. c# 2 Answers

Function that returns boolean and changes one of its parameters? 2 Answers

I need to return true after completing a tween animation.How should i do it ? 0 Answers

Re-using the "same" for loop? 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