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 Thomas-Hawk · Oct 02, 2017 at 04:58 PM · updateplayerprefsbooleanflipframe

Boolean Trouble, Please help....Boolean does not flip another boolean

Script A checks every frame to see if Script B has a boolean true, so that script A can flip its own boolean, every frame. Script B flips the bool, script A logs a debug line implying that it caught the flip, but the action which is supposed to trigger when the bool is true, (which would un-flip it afterwards) does not happen. Setting the boolean on script A manually, does trigger the action, just no idea why it would debug that and then not actually flip it.

"BS" is a script which, Clears player preferences, then re-saves a lot of structures, when a boolean, "saving", is true. When BS is done saving, it flips "saving" back to false.

I need "Slot" to recognize that "saving" has been flipped, so that "slot" can flip its own boolean on, called "flip", so that the slot can re-run its SaveItem function, which would be turning "flip" back off.

I can only get the slot to recognize that "bs.saving"

Here is the Update from the Slot script:

     public void Update(){
 
         if (bs.saving == true) {
             Debug.Log ("See BS SAVING true on slot"+gameObject.name);
             flip = true;
             Debug.Log ("Set FLIP to TRUE because BS was SAVING"+gameObject.name);
         }
         if (flip){
             Debug.Log ("WE ARE FLIPPED, ARE WE OCCUPIED?"+gameObject.name);
             //SaveItem ();
             if (slotOccupied == true) {
                 Debug.Log ("FLIPPED and OCCUPIED now SETTING BOOL AND SAVEITEM"+gameObject.name);
                 PlayerPrefsX.SetBool (gameObject.name + "Bool", true);
                 SaveItem ();
             }
 
         }
     }



Here is the update from the BuildingSaver script: void Update(){

         if (saving) {
             PlayerPrefs.DeleteAll ();
             buildings = 0;
             PlayerPrefs.SetInt ("howManyBuildings", 0);
             saving = false;
             SaveAll ();
         }
     }
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 MacDx · Oct 02, 2017 at 06:07 PM 1
Share

Hello @$$anonymous$$-Hawk I think you may have an update ti$$anonymous$$g problem here. You are trying to use at least 3 booleans there (saving, flip and slotOccupied) and 2 of them you are not even showing at what point in your code they're set, (slotOccupied not set to true or false and flip is never set to false, at least in the portion of the code that you are showing) so I can't really know what's happening without taking a look at the bigger picture.

I don't really like dabbling in boolean hell, so I have a suggestion. If you could tell me what are you trying to achieve with this whole saving system, I could try to come up with a different approach to achieve the same thing without using so many bools and update methods, and with the added benefit of keeping sanity in healthy levels :D trust me. You should stay away from booleans as "event switches", as much as possible.

avatar image BlakeSchreurs · Oct 02, 2017 at 06:27 PM 0
Share

The execution order of updates is undeter$$anonymous$$ed, so you'll end up with race conditions. It looks like what you're trying to create is a mutual exclusive lock. Take @$$anonymous$$acDx up on their offer to help re-engineer the code.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Coroutines and if statements 1 Answer

Change Bool When Audio Clip Ends C# 1 Answer

PlayerPrefs Problem crashing with SetBool 2 Answers

BoolPrefs Problem 2 Answers

Purchase Level Unlock System 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