Search Unity

Question Values not computing when variables are reset

Discussion in 'Scripting' started by Supershandy1, Dec 6, 2023.

  1. Supershandy1

    Supershandy1

    Joined:
    Nov 2, 2023
    Posts:
    10
    I'm at a bit of a loss with this one and not entirely sure what's going on. I have a code that calculates colour that runs perfectly fine when I run the first instance of it, but if I reset the values by pressing R, then running the code again, it doesn't seem to run the DatabaseSearch properly as the computed LAB and computed RGB values remain at 0

    I'm not entirely sure what's going on, any help would be appreciated

    Edit - Resolved as it turned out I just needed to attach the script to an object that I could create and destroy. This meant the values didn't become fixed.
     
    Last edited: Dec 9, 2023
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,784
    you need to debug it, check absolutely everything is reset and work out where it goes wrong
     
  3. Supershandy1

    Supershandy1

    Joined:
    Nov 2, 2023
    Posts:
    10
    Ok, I setup Debug.Log states for everything that gets reset.

    If I press S to start the program, it shows values in computedRGB. When I press R to Reset the variables, it shows computedRGB as 0 (along with everything else as set out).

    If I press S again, computedRGB still shows 0 even after DatabaseSearch is run (I know it's doing something because the program hangs while it's doing the for loop)
     
  4. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,784
    OK you say evrything gets reset but S seems to change the database... so, are you sure thats good? when i said debug, i meant, throw in a lot of commands to see where it goes and what its doing.. such as you mention the loop.. throw it in, step through it if you have to..
     
  5. Supershandy1

    Supershandy1

    Joined:
    Nov 2, 2023
    Posts:
    10
    Oh no, I added in the database removal and reinstating it as a troubleshooting step to see if that was the issue i.e unloading it then reloading it back in.

    I'm confused by the debug part though, all it is is entering an RGB code and pressing S. Regardless of what RGB I use, it still throws the same error. It just doesn't make sense why it will run on the first instance, but not again without resetting the player.

    I even tried manually rezeroing everything in the inspector without pressing R and it still gives the same issue. It goes through creating the XYZ and LAB, then just returns 0-0-0 when doing the SearchDatabase section rather than the closest RGB values it can find to the target.

    All the checkboxes go to true to show that it had completed the search as if it had been run the first time
     
  6. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,784
    so put in debug statements through that run through, see where it goes and what it gets, something is being skipped and you need to find why
     
  7. Supershandy1

    Supershandy1

    Joined:
    Nov 2, 2023
    Posts:
    10
    Ok, So putting the Debug.Log in the for loop in DatabaseSearch shows on the first run through that it's searching for codes, when I reset it and run it again the Debug.Log shows nothing at all, as if the for loop was never executed
     
  8. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,784
    there you go, now you know why it wasnt working
     
  9. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,637
    You should keep going. If the loop is not running, Debug.Log to see the values of data1.Length and databaseCurrent.text and all that.
     
  10. Supershandy1

    Supershandy1

    Joined:
    Nov 2, 2023
    Posts:
    10
    Tried that, Debug.log comes back with i being the value of the length of the database even after pressing R to reset and then press S.

    It seems to be getting stuck or skipping something that means it doesn't crossrefence anything against the database anymore. It's weird that it does it fine when the program is first initialised, but after that it just doesn't want to do it.
     
  11. Supershandy1

    Supershandy1

    Joined:
    Nov 2, 2023
    Posts:
    10
    Ok, I added in SceneManager.LoadScene as a reset, but this doesn't seem like a viable, long term solution.

    It is however...working.....

    Still, the question remains as to why, if I reset the values back to zero and search again, the for loop gets bypassed for crossreferencing and just goes through the whole database without doing anything
     
  12. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    1,784
    this is why you have to debug it, you need to watch what happens and follow it through its path.. spam the s*t out yourself with debug messages if necessary.