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 /
  • Help Room /
avatar image
0
Question by CraniumCode · Nov 15, 2015 at 10:28 PM · c#booleanfunctions

Boolean seemingly changing out of thin air C#

My code was running perfectly, but all of a sudden things started to go awry. For some reason, one of my booleans will just switch from false to true and vice versa, even though there is no code that would make it do such a thing. You can see in the code below that I have a print statement at the top and at the bottom, and although they should both print out the same boolean value, they do not. The update function is the only function running in this script, so I don't know why this is happening. Any suggestions as to what I should do will be greatly appreciated.

alt text

         void Update () {
 
         print ("6: " + seaweed1Started);
         if (true) {
             seaweed1Started = objectPlacement (seaweed1, 200, seaweed1Started, 0);
             }
         print ("5: " + seaweed1Started);
         }


screen-shot-2015-11-15-at-52552-pm.png (13.8 kB)
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 pekalicious · Nov 15, 2015 at 11:56 PM

"even though there is no code that would make it do such a thing."

You do have code that would make it do such a thing:

 seaweed1Started = objectPlacement (seaweed1, 200, seaweed1Started, 0);

You are calling the objectPlacement method and setting your boolean variable seaweed1Started to whatever it returns. What has changed in objectPlacement?

Also, there's no need to write if (true) because that statement will always be true. Is that temporary code, or are you trying to express something in code that you are not sure how?

Comment
Add comment · Show 5 · 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 CraniumCode · Nov 16, 2015 at 12:20 AM 0
Share

The objectPlacement method does change the seaweed1Started boolean, but not between the print statements that are executed. Once the print statement "5" prints, the update function automatically loops back around and prints the "6" statement, not ever running the objectPlacement method.

In regard to the if(true), I was testing out whether methods in the if statement were executed in order or all at once, and I forgot to get rid of it.

avatar image pekalicious CraniumCode · Nov 16, 2015 at 12:29 AM 0
Share

Ah, silly me, good point. $$anonymous$$issed that. So where is seaweed1Started co$$anonymous$$g from? Is it a static variable? Who else has access to it and changes it?

avatar image CraniumCode pekalicious · Nov 16, 2015 at 12:37 AM 0
Share

Seaweed1Started is not static and it's initialized at the top of the script. Nothing else has access to it and nothing else can change it, other than whatever is causing me this grief.

Show more comments
avatar image
0

Answer by CraniumCode · Nov 16, 2015 at 01:56 AM

@pekalicious The script is only going to be used in one place on one gameObject

Comment
Add comment · Show 1 · 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 pekalicious · Nov 16, 2015 at 02:02 AM 0
Share

Hmmm.. It's weird that making it static worked. I'm sure there's more to this, but since there is only gonna be one, then you should be fine for now.

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

34 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

Related Questions

Changing Variables on one script with multiple other scripts 1 Answer

How do I Effect a whole Array of GameObjects' Scripted Boolean? 0 Answers

PLEAASEE I NEED HELP!!! How to turn Mesh Renderer of cubes on and off by pushing buttons? 1 Answer

How can i pass a method like a parameter Unity3d C#? 3 Answers

animator boolean 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