Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

(SOLVED) Boolean change not being reflected in Update()

Discussion in 'Scripting' started by JNoob, Dec 17, 2019.

  1. JNoob

    JNoob

    Joined:
    Jan 9, 2018
    Posts:
    6
    Hi all,

    I have this really weird problem with a boolean, I'm hoping someone can help with.

    I'm setting a boolean value to True in a Cinemachine's 'On Camera Live' event via a property. The boolean property's set contains code to call a particular method which starts a countdown to the level of my game starting. A debug in this method shows that the method is being called and the value of the boolean is being set to True. With me so far?

    Ok, so in Update() there is a check that the game is running and not paused, and then checks to see if the coundown should start via this boolean. But the update function always returns this value as false, so the condition is never met, hence the countdown does not start.

    The inspector displays the boolean, but the tick box is not changed when the property is changed to true. If I manually put a tick in the box, the countdown continues as expected.

    Here's the code:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class GameManager : MonoBehaviour
    5. {
    6.     public static GameManager Instance;
    7.    
    8.     private bool countdownStarted;
    9.     private bool gameIsRunning = false;
    10.     private bool gameIsPaused = false;
    11.  
    12.     public bool GameIsRunning { get => gameIsRunning; set => gameIsRunning = value; }
    13.     public bool GameIsPaused { get => gameIsPaused; set => gameIsPaused = value; }
    14.     public bool CountdownStarted {
    15.         get => countdownStarted;
    16.         set {
    17.             countdownStarted = value;
    18.             if (countdownStarted) {
    19.                 StartCountdown();
    20.             }
    21.         }
    22.     }
    23.  
    24.     private void Awake()
    25.     {
    26.         if (Instance == null) {
    27.             Instance = this;
    28.             DontDestroyOnLoad(this);
    29.         }
    30.         else { Destroy(gameObject); }
    31.     }
    32.  
    33.     void Start()
    34.     {
    35. #if UNITY_ANDROID
    36.         Screen.sleepTimeout = SleepTimeout.NeverSleep;
    37. #endif
    38.         ResetCountdownFlags();
    39.         GameIsRunning = true;
    40.     }
    41.  
    42.     private void Update()
    43.     {
    44.         if (GameIsRunning && !GameIsPaused) {
    45.             // CountdownStarted = true; // Works if it's set here
    46.             Debug.Log($"Update() countdownStarted set to {CountdownStarted}"); // Should eventually change to True, doesn't
    47.             if (CountdownStarted) { // Why is this not registering the fact that the bool value has changed to True in StartCountdown() ?
    48.                 countdownTimer -= Time.deltaTime;
    49.                 UIManager.Instance.UpdateCountdownPanel((int)countdownTimer);
    50.                 if (countdownTimer <= 0.0f) {
    51.                     CompleteCountdown();
    52.                 }
    53.             }
    54.             else {
    55.                 // Countdown complete, level starting
    56.                 //gameTimer += Time.deltaTime;
    57.             }
    58.  
    59.         }
    60.         //TODO: move the gameTimer to the commented line in the else block above
    61.         gameTimer += Time.deltaTime; //Placed Here For Testing Only
    62.     }
    63.  
    64.     public void StartCountdown()
    65.     {
    66.         Debug.Log($"Starting Countdown, countdownStarted now set to {CountdownStarted}"); // This prints True, as expected
    67.         UIManager.Instance.ShowCountdownPanel();
    68.         SoundFXManager.Instance.PlayCountdown();
    69.     }
    70.  
    71.     private void ResetCountdownFlags()
    72.     {
    73.         CountdownStarted = false;
    74.         countdownTimer = countdownDuration;
    75.     }
    76.  
    77.     private void CompleteCountdown()
    78.     {
    79.         ResetCountdownFlags();
    80.         Debug.Log($"Ended Countdown, countdownStarted now set to {CountdownStarted}"); // This prints False, as expected
    81.         UIManager.Instance.HideCountdownPanel();
    82.     }
    83. }
    I really hope someone with a bigger brain than me can help shed some light on this 'cause after spending three days trying to work this out, my head is hurting.

    Thanks in advance,
    Jay
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,697
    What is countdownDuration? Are you sure that it's something greater than 0?
     
  3. JNoob

    JNoob

    Joined:
    Jan 9, 2018
    Posts:
    6
    HI,

    Yes, countdownDuration is set in the inspector to 3.

    Thanks for asking,
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,697
    I don't see a definition for it in your code. Did you post the whole code?
     
    Joe-Censored likes this.
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Add debugging everywhere you set CountdownStarted to false, such as ResetCountdownFlags. Also verify you don't have multiple instances of this script in your scene.
     
  6. JNoob

    JNoob

    Joined:
    Jan 9, 2018
    Posts:
    6
    Kdgalla & Joe,

    Thanks for getting back to me. I've spent the past three days doing exactly what you suggested Joe,also, this class is a singleton so there's only ever one instance.

    Kdgalla, you're right, this isn't the whole code, it became a mess with all of the debug.log's and other attempts to track down the bug. I stripped the class back down to it's basics with only the relevent parts to the countdown to make it easier to read, but forgot the:
    Code (CSharp):
    1. [SerializeField] private float countdownDuration = 3f;
    prior to pasting into my original post.

    Thanks,
    Jay
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Well, the bool doesn't change to false on its own. If you add debugging next to every place you set it to false, you will see the debugging appear prior to where you expect it to be true but it is not. Either that or it is not being set to true when you expect it to be.
     
  8. JNoob

    JNoob

    Joined:
    Jan 9, 2018
    Posts:
    6
    Hi Joe,

    again, some good points. However, the bool is being set where I expect it to be set. The setter has a condition (line 22 below) that when met (the bool being set to true) fires off the StartCountdown() method. The debug line in this method (line 73) displays that the bool is set to True, the UIManager displays the countdown panel and the SoundFXManager plays the desired audio. All as expected.

    It should follow that the condition in the Update method (line 51) is then met and entered. However the debug.log in the outer condition (line 50) continues to report that the bool is false, and the else condition (line 58) is continually met (another debug.log added in here to prove that this is the case at line 61).

    Only if the bool is set by the inspector (ticking the box) does the countdown continue as expected and all debug lines report back as you would expect.

    I've looked for all references to the boolean, both itself and the property, and the only references are the ones expected, there's no erroneous references in the UIManaager, for example.

    Here's a slightly updated code to show all the debugs in place and what they return.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class GameManager : MonoBehaviour
    5. {
    6.     public static GameManager Instance;
    7.  
    8.     private float gameTimer = 0.0f;
    9.  
    10.     [SerializeField] private float countdownDuration = 3f;
    11.  
    12.     private bool countdownStarted;
    13.     private bool gameIsRunning = false;
    14.     private bool gameIsPaused = false;
    15.  
    16.     public bool GameIsRunning { get => gameIsRunning; set => gameIsRunning = value; }
    17.     public bool GameIsPaused { get => gameIsPaused; set => gameIsPaused = value; }
    18.     public bool CountdownStarted {
    19.         get => countdownStarted;
    20.         set {
    21.             countdownStarted = value;
    22.             if (countdownStarted) {
    23.                 StartCountdown();
    24.             }
    25.         }
    26.     }
    27.  
    28.     private void Awake()
    29.     {
    30.         if (Instance == null) {
    31.             Instance = this;
    32.             DontDestroyOnLoad(this);
    33.         }
    34.         else { Destroy(gameObject); }
    35.     }
    36.  
    37.     void Start()
    38.     {
    39. #if UNITY_ANDROID
    40.         Screen.sleepTimeout = SleepTimeout.NeverSleep;
    41. #endif
    42.         ResetCountdownFlags();
    43.         GameIsRunning = true;
    44.     }
    45.  
    46.     private void Update()
    47.     {
    48.         if (GameIsRunning && !GameIsPaused) {
    49.             // countdownStarted = true; // Works if it's set here
    50.             Debug.Log($"Update() countdownStarted set to {countdownStarted}"); // Should eventually change to True, doesn't
    51.             if (countdownStarted) { // This condition is never met, despite the bool being changed to True
    52.                 countdownTimer -= Time.deltaTime;
    53.                 UIManager.Instance.UpdateCountdownPanel((int)countdownTimer);
    54.                 if (countdownTimer <= 0.0f) {
    55.                     CompleteCountdown();
    56.                 }
    57.             }
    58.             else {
    59.                 // This debug line should stop printing once the above contition is met positively
    60.                 // and continue printing after the ResetCountdownFlags() method completes
    61.                 Debug.Log($"Update has entered the else condition"); // Constantly printing
    62.                 // Countdown complete, level starting
    63.                 //gameTimer += Time.deltaTime;
    64.             }
    65.  
    66.         }
    67.         //TODO: move the gameTimer to the commented line in the else block above
    68.         gameTimer += Time.deltaTime; //Placed Here For Testing Only
    69.     }
    70.  
    71.     public void StartCountdown()
    72.     {
    73.         Debug.Log($"Starting Countdown, countdownStarted now set to {countdownStarted}"); // This prints True, as expected
    74.         UIManager.Instance.ShowCountdownPanel();
    75.         SoundFXManager.Instance.PlayCountdown();
    76.     }
    77.  
    78.     private void ResetCountdownFlags()
    79.     {
    80.         CountdownStarted = false;
    81.         Debug.Log($"ResetCountdownFlags() setting CountdownStarted to {countdownStarted}"); // This prints False, as expected
    82.         countdownTimer = countdownDuration;
    83.     }
    84.  
    85.     private void CompleteCountdown()
    86.     {
    87.         Debug.Log($"Ended Countdown, resetting countdown flags"); // Calling the ResetCountdownFlags() method
    88.         ResetCountdownFlags();
    89.         UIManager.Instance.HideCountdownPanel();
    90.     }
    91. }
    I've searched through the entire project for 'CountdownStarted = false;' (without matching case, to catch all matches) and this bool is only being set to false in the ResetCountdownFlags() method, which, as shown by the debug.logs, is only being called once when the end of the coundown is reached, and only then after having to set the boolean value in the inspector as it's failed again !!

    If line 49 is uncommented, the condition is met and the countdown happens as it should (although at the wrong time, without the UI and Sound Managers doing their thing).

    I've had debug lines reporting back at every step of the way within this process, all reporting back as expected, until the condition in the Update method. I've also deleted the GameManager script from the project entirely and recreated it from scratch in case there was some weird bug, frankly I'm at a loss of where to go from here.

    Thanks again,
    Jay
     
  9. JNoob

    JNoob

    Joined:
    Jan 9, 2018
    Posts:
    6
    Thanks to Joe * Kdgalla for their input & help.

    This is now working !!

    Note for future self (and anyone else having the same problem):

    All it took to fix this was changing the class variable countdownStarted (Line 12 in the code list of my previous post) to be a static variable !
    Code (CSharp):
    1. private static bool countdownStarted;
    I honestly have no idea why this was the case, as a class variable was well within it's scope. If anyone else has any insight into why a static variable would make the difference, I'd love to hear your thoughts !! :)
     
  10. lambch0p

    lambch0p

    Joined:
    Oct 22, 2014
    Posts:
    62
    I've just had exactly the same issue.


    Code (CSharp):
    1. private bool _gameOver = false;
    2.  
    3. public void GameOver() {
    4.      _gameOver = true;
    5. }
    6.  
    7. private void Update() {
    8.     Debug.Log(_gameOver);
    9. }
    The GameOver method is called from one place, and only once. If I put a breakpoint in the GameOver method I can see that _gameOver gets set to true. However, the debug log in Update never prints 'true'. If I make _gameOver static, then the Update method prints the correct value.
     
  11. omx-jonson

    omx-jonson

    Joined:
    Mar 23, 2014
    Posts:
    17
    Thanks for your help, I actually had the same problem. I'm not new to programming and I do understand how C# works, however I ran into this particular bug where the value of a bool after setting to true, was immediately changed back to false by god only knows what. I literally set it in one place, and in LateUpdate it's false, false, false. Changing the variable to static solves the issue. Weird.
     
  12. Beezer505

    Beezer505

    Joined:
    Dec 10, 2020
    Posts:
    1
    JNoob, thank you so much! I had the same problem and would have never gotten to this solution on my own. You saved me so much time troubleshooting this issue.
     
  13. Mogho-Studio

    Mogho-Studio

    Joined:
    Jun 12, 2019
    Posts:
    1

    Thank you!!!. it worked for me :D
     
  14. kayalafridi

    kayalafridi

    Joined:
    Apr 24, 2020
    Posts:
    1
    Hello! I am writing it here to let you know of a similar situation I managed to solve.

    In my case, I was working with a class named DialogActor which was not a singleton and I really needed the bool property in it to be non-static for my system to work. The bool property in my class, when set from within the class worked properly but, when set from the outside through an instance, did not seem to work in Update method although the Debug.Log in the setter method reported the correct result.

    After a lot of searching, I managed to find the source of the problem. In a different manager-like singleton class, I was storing the reference to the objects having the DialogActor component and this was my primary source of accessing all the DialogActor objects in the scene. The problem was that during instantiation, I Instantiated the object from the prefab in the scene but assigned the prefab itself as the DialogActor object reference instead of the instantiated object in my manager class.

    So I ended up in a situation where, the object was placed in the scene and I kept updating the prefab waiting to see the changes in the scene object.
    This explains why Update reported false results as it was only operating on the scene object whereas the setter method reported the correct thing but it was being called on the prefab.

    So, make sure you are updating the correct scene object and not a prefab that is not even placed in the scene.
     
    scorpioservo likes this.
  15. IanMcIntosh

    IanMcIntosh

    Joined:
    Dec 2, 2021
    Posts:
    2
    OMG! This bug was KILLING me. Thanks so much for the solution.
     
  16. ms502040

    ms502040

    Joined:
    Jan 9, 2019
    Posts:
    18
    Static fields of a non-static class is shared across all the instances. So, changes done by one instance would reflect in others!!!!
    Question to UNITY team: in override void Update() I can not get real value (updated outside update method) of NON static property - this is bug or feature???
     
    mars_gamedev and efge like this.
  17. mars_gamedev

    mars_gamedev

    Joined:
    Oct 2, 2019
    Posts:
    1
    Static fixed this for me... I want my two hours of my life back lol. I had 'private bool _driving' being set by an event in an InputHandler class perfectly fine. Yes, I made an InputHandler prefab containing that component and threw an instance in my scene. _driving showed up true when I debugged the listener that set it true. Then when Player Input called the function that referenced '_driving' it was showing up true in the inspector and false in the debug I put in the function referencing it. FEATURE OR BUG?
     
    rmele09 likes this.
  18. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,192
    It's neither a bug nor a feature. It's you're making mistakes. You said you made your InputHandler a prefab and made an instance of that prefab in the scene. So you have "two" actual seperate objects in your project. The first one is the instance in the scene, the other one is the prefab in your project. You most likely have linked an event to the prefab object instead the instance in the scene. So changing a boolean in a prefab would not change the boolean in the instance in the scene.

    Whenever you're unsure about which objects you're dealing with, the Debug.Log method can take a second optional argument which can be any UnityEngine.Object derived type which acts as context object. The point is when you click on the log message in the console, the Unity editor will ping / highlight the context object in the hierarchy / project panel so you know what object the message belongs to. So when putting Debug.Log statements in your code, add "this" as second argument and click the log message to see from which object the message was created. I can guarantee you, that you have linked the wrong object in your code / event and that you actually run code on your prefab instead of the instance in your scene.
     
  19. S4nt1n0

    S4nt1n0

    Joined:
    Jan 4, 2024
    Posts:
    1
    Hi guys I've been working with a project for a game development. I've set some private bool but they aren't showing inside my script path inside unity the code is down below it is still under development so I wanna know where the problem is:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.     private float movementInputDirection;
    8.  
    9.     private bool isFacingRight = true;
    10.  
    11.     private bool isWalking;
    12.  
    13.     private bool isGrounded;
    14.  
    15.     private bool canJump;
    16.  
    17.     private Rigidbody2D rb;
    18.  
    19.     private Animator anim;
    20.  
    21.     private float movementSpeed = 10.0f;
    22.  
    23.     public float jumpForce = 16.0f;
    24.  
    25.     public float groundCheckRadius;
    26.  
    27.     public Transform groundCheck;
    28.  
    29.     public LayerMask whatIsGround;
    30.  
    31.     // Start is called before the first frame update
    32.     void Start()
    33.     {
    34.         rb = GetComponent<Rigidbody2D>();
    35.         anim = GetComponent<Animator>();
    36.     }
    37.  
    38.     // Update is called once per frame
    39.     void Update()
    40.     {
    41.         CheckInput();
    42.         CheckMovementDirection();
    43.         UpdateAnimations();
    44.         CheckIfCanJump();
    45.     }
    46.  
    47.     private void FixedUpdate()
    48.     {
    49.         ApplyMovement();
    50.         CheckSurroundings();
    51.     }
    52.  
    53.     private void CheckSurroundings()
    54.     {
    55.  
    56.         isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
    57.  
    58.     }
    59.  
    60.     private void CheckIfCanJump()
    61.     {
    62.         if (isGrounded && rb.velocity.y <= 0)
    63.         {
    64.  
    65.             canJump = true;
    66.  
    67.         }
    68.  
    69.         else
    70.         {
    71.  
    72.             canJump = false;
    73.  
    74.         }
    75.  
    76.     }
    77.  
    78.     private void CheckMovementDirection()
    79.     {
    80.         if(isFacingRight && movementInputDirection < 0)
    81.         {
    82.             Flip();
    83.         }
    84.         else if (!isFacingRight && movementInputDirection > 0)
    85.         {
    86.             Flip();
    87.         }
    88.  
    89.         if(rb.velocity.x  !=0)
    90.         {
    91.  
    92.             isWalking = true;
    93.  
    94.         }
    95.         else
    96.         {
    97.  
    98.             isWalking = false;
    99.  
    100.         }
    101.    
    102.     }
    103.  
    104.     private void UpdateAnimations()
    105.     {
    106.  
    107.         anim.SetBool("isWalking", isWalking);
    108.  
    109.     }
    110.     private void CheckInput()
    111.     {
    112.         movementInputDirection = Input.GetAxisRaw("Horizontal");
    113.  
    114.         if (Input.GetButtonDown("Jump"))
    115.         {
    116.             Jump();
    117.         }
    118.     }
    119.  
    120.     private void Jump()
    121.     {
    122.         if (canJump)
    123.         {
    124.  
    125.             rb.velocity = new Vector2(rb.velocity.x, jumpForce);
    126.  
    127.         }  
    128.     }
    129.  
    130.     private void ApplyMovement()
    131.  
    132.     {
    133.         rb.velocity = new Vector2(movementSpeed * movementInputDirection, rb.velocity.y);
    134.     }
    135.  
    136.     private void Flip()
    137.     {
    138.         isFacingRight = !isFacingRight;
    139.         transform.Rotate(0.0f, 180.0f, 0.0f);
    140.     }
    141.  
    142.     private void OnDrawGizmos()
    143.     {
    144.  
    145.         Gizmos.DrawWireSphere(groundCheck.position, groundCheckRadius);
    146.  
    147.     }
    148.  
    149. }
     
  20. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,369


    Please don't necro-post. If you have a new question, make a new post. It's FREE!!




    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, log output, variable values, and especially any errors you see
    - links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

    The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven't put effort into finding the documentation, why should we bother putting effort into replying?



    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    - Do not TALK about code without posting it.
    - Do NOT post unformatted code.
    - Do NOT retype code. Use copy/paste properly using code tags.
    - Do NOT post screenshots of code.
    - Do NOT post photographs of code.
    - Do NOT attach entire scripts to your post.
    - ONLY post the relevant code, and then refer to it in your discussion.




    If you need more information about what your program is doing as well as how and where it is deviating from your expectations, that means it is...



    Time to start debugging!

    By debugging you can find out exactly what your program is doing so you can fix it.

    Here is how you can begin your exciting new debugging adventures:

    You must find a way to get the information you need in order to reason about what the problem is.

    Once you understand what the problem is, you may begin to reason about a solution to the problem.

    What is often happening in these cases is one of the following:

    - the code you think is executing is not actually executing at all
    - the code is executing far EARLIER or LATER than you think
    - the code is executing far LESS OFTEN than you think
    - the code is executing far MORE OFTEN than you think
    - the code is executing on another GameObject than you think it is
    - you're getting an error or warning and you haven't noticed it in the console window

    To help gain more insight into your problem, I recommend liberally sprinkling
    Debug.Log()
    statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the names of the GameObjects or Components involved?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?
    - are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

    Knowing this information will help you reason about the behavior you are seeing.

    You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as
    Debug.Log("Problem!",this);


    If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

    You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

    You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer for iOS: https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ or this answer for Android: https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/

    If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

    Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

    If your problem is with OnCollision-type functions, print the name of what is passed in!

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494

    If you are looking for how to attach an actual debugger to Unity: https://docs.unity3d.com/2021.1/Documentation/Manual/ManagedCodeDebugging.html

    "When in doubt, print it out!(tm)" - Kurt Dekker (and many others)

    Note: the
    print()
    function is an alias for Debug.Log() provided by the MonoBehaviour class.
     
    Bunny83 likes this.
  21. kylesmithsystems

    kylesmithsystems

    Joined:
    May 7, 2024
    Posts:
    7
    I just had the same issue! ChatGPT did not have the answer but you did, you son of a gun! Thanks man for documenting these shenanigans. Hooray! Huzzah! Who would of known that just making variable static would of solved all the errors and headaches!? Wow.