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 FlashX · Feb 11, 2015 at 01:57 AM · errorienumerator

Narf question on scope - I think :/

ok so I think i'm a bit narf on understanding this.

ive got a IEnumerator with a variable in it. I also have a function that i'm trying to run from the IEnumerator which has the variable in it.

my problem is that i'm getting this error:

error CS0103: The name `theVar' does not exist in the current context

I know I probably should know the answer to this but I don't. can someone explain it in english for me?

cheers

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

1 Reply

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

Answer by Alanisaac · Feb 11, 2015 at 02:04 AM

Do you mean you have something like the code below? That code will not compile because the variable name you pass to the function "notTheSameVarName" is different than the variable name you use in the enumerator "theVar". How is MyOtherMethod supposed to know what theVar is?

     IEnumerator MyMethod()
     {
         var theVar = new int ();
         MyOtherMethod (theVar);
         yield return WaitForSeconds (5);
     }
 
     void MyOtherMethod(int notTheSameVarName)
     {
         theVar += 1;
     }


I could be totally off here depending on what your code is, so posting your enumerator and method code would probably help if that isn't the case :).

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 FlashX · Feb 11, 2015 at 02:10 AM 0
Share

Hi Alfalfasprout,

thanks for posting.

yeah that’s exactly the structure of code I have.

so I guess my next question is, how can I make a variable global so that it can be accessed anywhere? Is it possible?

cheers

avatar image Alanisaac FlashX · Feb 11, 2015 at 02:19 AM 2
Share

You might want to look at some of the basic scripting tutorials on variables and functions for Unity.

If that all makes sense or feels like old news, then skip ahead a few videos to scope and access modifiers, which might help you with some of the variable scope issues you've been having.

The two videos together shouldn't take you much more than 10 $$anonymous$$utes.

avatar image FlashX FlashX · Feb 11, 2015 at 02:32 AM 0
Share

ah buddy! I think you’ve answered so many questions for me! Thank you so much for this! :)

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

20 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

Related Questions

error CS0161: not all code paths return a value 2 Answers

How can I spawn different GameObjects using IEnumerator? 1 Answer

Loop with WaitForSeconds in IEnumerator appears to be incorrect by 10-15% 2 Answers

Presistent Object Inconsistency error 0 Answers

Missing Reference Exception 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