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 Batka · Dec 02, 2016 at 09:51 AM · booleanreferencelevelboolbooleans

Boolean somehow becomes false. And an Integer zero.

Hey guys,

Okay so I have this bug that I really don't get the logic off. It's either something ultra stupid, or something stack related I don't yet understand...

        public void LevelLoad(Level lev)
         {
 #if UNITY_ANDROID && !UNITY_EDITOR && !UNITY_IOS
             _audioManager.ReleasePool();
 #endif
             currentlyDisappearedFigures = 0;
             if (!lev.Equals(currentLevel))
             {
                 currentLevel = lev;
                 //lev.transparentQTY = 0; lev.normalQTY = 0; lev.totalQTY = 0;
                 //lev.hasDeath = false; lev.hasND = false; lev.hasNormal = false; lev.hasTransparent = false;
                 foreach (Figure fig in lev.Figures)
                 {
                     if (fig._figureType != null)
                     {
                         if (fig._gameObject.CompareTag("Hard"))
                             fig._figureType.ResetHard();
                         fig._figureType.RefreshFigure();
                         lev.totalQTY++;
                     }
                     Debug.Log("HasNormal-" + lev.hasNormal + ",normalQTY-" + lev.normalQTY + ",hasTransparent-" +
                     lev.hasTransparent + ",transparentlQTY-" + lev.transparentQTY + ",hasND-" +
                     lev.hasND + ",hasDeath-" + lev.hasDeath);
                 }
                 
 
                 if (lev.Hint != null)
                     lev.Hint.SetActive(false);
 
                 isCurrentLevelPassed = false;
             }
 #if UNITY_ANDROID && !UNITY_EDITOR && !UNITY_IOS
             if (currentLevel.totalQTY > 22)
                 currentLevel.totalQTY = 22;
             _audioManager.CreatePool(lev.totalQTY + 1);
             Debug.Log("currentLeve.totalQTY-" + currentLevel.totalQTY);
 
             _audioManager.LoadAudio(currentLevel.hasNormal, currentLevel.normalQTY,
                 currentLevel.hasTransparent, currentLevel.transparentQTY,
                 currentLevel.hasND, currentLevel.hasDeath);
             Debug.Log("hasNormal-" + currentLevel.hasNormal + ",normalQTY-" + currentLevel.normalQTY + ",hasTransparent-" +
                 currentLevel.hasTransparent + ",transparentlQTY-" + currentLevel.transparentQTY + ",hasND-" +
                 currentLevel.hasND + ",hasDeath-" + currentLevel.hasDeath);
 
 #endif
 }

See the:

 Debug.Log("HasNormal-" + currentLevel.hasNormal + ",normalQTY-" + currentLevel.normalQTY 
 + ",hasTransparent-" + currentLevel.hasTransparent 
 + ",transparentlQTY-" + currentLevel.transparentQTY
 + ",hasND-" + currentLevel.hasND 
 + ",hasDeath-" + currentLevel.hasDeath);



All of those print either FALSE, or ZERO, and I don't know why.


The thing is, I am instantiating them in:

 fig._figureType.RefreshFigure();


Here is the inside of FigureType.RefreshFigure(). It's irrelevant, but the Debug.Log inside it shows different values from the one I mentioned above:

     public void RefreshFigure()
     {
         gameObject.SetActive(true);
         Level currentLevel = GameManager.Instance.GetCurrentLevel();
         _collider.enabled = true;
         if(_type != FigType.Death && _type != FigType.Transparent)
             _collider.isTrigger = false;
         ResetTransform();
         
 
 
         if (_type == FigType.Normal)
         {
             currentLevel.hasNormal = true;
             currentLevel.normalQTY++;
             Debug.Log("Current Level hasNormal inside RefreshFigure(): " + currentLevel.hasNormal);
             Debug.Log("Current Level Normal QTY inside RefreshFigure(): " + currentLevel.normalQTY);
         }
         if (_type == FigType.Transparent)
         {
             currentLevel.hasTransparent = true;
             currentLevel.transparentQTY++;
         }
         if (_type == FigType.Hard)
         {
             currentLevel.hasNormal = true;
             for(int i = 0; i < hardLives; i++)
                 currentLevel.normalQTY++;
         }
         if (_type == FigType.NotDisappear)
             currentLevel.hasND = true;
         if (_type == FigType.Death)
             currentLevel.hasDeath = true;
 
         StartCoroutine(Tools.MakeTransparent(_spriteRenderer, 1, 0.5F));
         Debug.Log("Current Level hasNormal on end of RefreshFigure(): " + currentLevel.hasNormal);
         Debug.Log("Current Level Normal QTY on end of RefreshFigure(): " + currentLevel.normalQTY);


Here, take a look at my log entry:

http://prnt.sc/ddrbqr


Here are some notes I'd like to say about this:

Level is a struct, not a class.

I've removed annotations like #if UNITY_ANDROID, just to check if those are the reason.

I've also tested on Android device, same bug.

Here are all references to the boolean .hasNormal, none of which sets it to false:

http://prntscr.com/ddrf5e

Please guys, make me feel stupid. :)

Thanks a lot for your time!

TL;DR: Boolean doesn't wan't to become true, integer won't increase.

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 christoph_r · Dec 01, 2016 at 10:16 AM 0
Share

Please cut down the code to the parts that are directly related and consider tracking just one variable. However, as false and 0 are the default values for bool and int, I suspect your variables never get initialised or written to.

avatar image hexagonius · Dec 02, 2016 at 05:11 PM 0
Share

You said it yourself, Level is a struct, not a class. In RefreshFigure, you get a COPY of the level with

 Level currentLevel = Game$$anonymous$$anager.Instance.GetCurrentLevel();

Then you're altering all the values but you never write them back, which is the missing step in this case (struct)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

If statement not working 1 Answer

Call a function When a bool changes value? 2 Answers

Referenced Bool is not updating 1 Answer

Building a Face Generator, need to destroy previous instance after pressing key a second time 0 Answers

Trying to establish turn order in my game but bool will not toggle properly 0 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