Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how to use an if statement in a button press void?

Discussion in 'Scripting' started by JDVDeisgn, Apr 11, 2016.

  1. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    Code (CSharp):
    1. public void choose(){
    2.  
    3.         if (manager.rpc == 1 && manager.pcc == 0) {
    4.  
    5.             manager.begin = 1;
    6.  
    7.         }
    8. }
    both of the values are what they need to be but on the button press the void isn't executed. the onclick is set up correctly in the inspector but as it's not working would suggest I haven't set it up right in the script
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    add debug.log lines at the beginning of the function to output the two things you are checking in the if statement.

    If nothing comes out, you're not calling the script correctly from the button onclick event. If something does come out you know what the parameters are for the if and can check them.

    basic debugging is something you can't really get other people to do...
     
  3. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    I have debugged the first two values in the if statement. it's just not changing the begin value to one so wondered where I was going wrong in the script. ofc I've used basic debugging...

    this kind of attitude really isn't needed
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    there is no indication in your OP that that has been done. You've posted a basic 5 line script and said (paraphrasing) "it's setup right but it's not working"...

    anyway, there is nothing in the OP script which appears to be wrong. Is the manager.begin values altered anywhere else? perhaps it's being set to 1 here and reset to something else in another script? have you debugged the begin value immediately after you've set the value in the above script?
     
  5. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    I just checked again and debugged the begin value and it's changing to one

    Code (CSharp):
    1. if (manager.begin == 1) {
    2.  
    3.             some things
    4.  
    5.         }
    however it isn't executing the things I ask it to when begin becomes one for some reason :/ the things do get executed however when I just include the some things (obviously they are actual events in my script) in
    Code (CSharp):
    1. public void choose(){
    2.  
    3. some things
    4.  
    5. }
    it works :/

    there isn't anything else affecting the begin value and even if there was it says its value is 1 in the debug so idk what's happening
     
  6. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    I figured that out and it was something really buggy within unity that was causing it but getting many more bugs. unity is extremely buggy
     
  7. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I doubt very much that your issue was caused by a bug in Unity. If you believe that to be the case then I'd highly suggest posting how to recreate this bug here so that other folks can try to do it and then filing a bug report.
     
  8. JDVDeisgn

    JDVDeisgn

    Joined:
    Oct 17, 2015
    Posts:
    148
    many things in unity are very broken and this is widely known. a lot of the time working in unity is about working past the bugs/how broken it is
     
  9. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539