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:
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:
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.
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.
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)
Your answer
Follow this Question
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