Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Zitoox · Jul 08, 2016 at 01:46 AM · scripting problemerror message

Problem with cheatcode

I am trying to make a script that when the player types "TILT" in sequency, the game changes to a new scene. BUT i am having a lot of problems, as usual T.T

I found this script in the forum and i update it, but it doesn't work because of some problems.

 using UnityEngine;
 using System.Collections;
 
 public class eastereggscene : MonoBehaviour {
 
     private string[] cheatCode;
     private int index;
 
     void Start()
     {
         // Code is "tilt", user needs to input this in the right order
         cheatCode = new string[] { "t", "i", "l", "t"  };
         index = 0;
     }
 
     void Update()
     {
         // Check if any key is pressed
         if (Input.anyKeyDown)
         {
             // Check if the next key in the code is pressed
             if (Input.GetKeyDown(cheatCode[index]))
             {
                 // Add 1 to index to check the next key in the code
                 index++
            { 
             // Wrong key entered, we reset code typing
             else {
                 index = 0;
             }
         }
 
         // If index reaches the length of the cheatCode string, 
         // the entire code was correctly entered
         if (index == cheatCode.Length)
 
            }
             else
             {
                 //load level
                 Application.LoadLevel(1);
             }
         }

The following errors appear:

Assets/eastereggscene.cs(26.12): Error CS1525: Unexpected Symbol '{' Assets/eastereggscene.cs(37.12): Error CS1525: Unexpected Symbol '}'

If i remove those keys, (i don't know if this is the correct name, english is not my mother language), i get these errors:

Assets/eastereggscene.cs(28.16): Error CS1525: Unexpected Symbol 'else' Assets/eastereggscene.cs(38,16): Error CS1525: Unexpected Symbol 'else'

What is wrong?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OrkhanAlikhanov · Jul 08, 2016 at 02:03 AM 1
Share

You misused curly brackets At line 26 change '{' to '}' and at line 36 add '{'

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by TheFish657 · Jul 09, 2016 at 12:42 PM

you missed out a few curly brackets and a semi-colon. Here's the code

  using UnityEngine;
  using System.Collections;
   
   public class eastereggscene : MonoBehaviour 
   {
       private string[] cheatCode;
       private int index;
   
       void Start()
       {
           // Code is "tilt", user needs to input this in the right order
           cheatCode = new string[] { "t", "i", "l", "t"  };
           index = 0;
       }
   
       void Update()
       {
           // Check if any key is pressed
           if (Input.anyKeyDown)
           {
               // Check if the next key in the code is pressed
               if (Input.GetKeyDown(cheatCode[index]))
               {
                   index++;
               }
               // Wrong key entered, we reset code typing
               else 
               {
                   index = 0;
               }
           }
   
           // If index reaches the length of the cheatCode string, 
           // the entire code was correctly entered
           if (index == cheatCode.Length)
           {
               Application.LoadLevel(1);
           }
       }
   }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zitoox · Jul 09, 2016 at 09:10 PM 0
Share

Thanks! Everyone's code was incorrect too but you fixed it! =)

avatar image
0

Answer by Fire_Cube · Jul 08, 2016 at 08:01 AM

You do a few syntax error there, let me fix this :)

  using UnityEngine;
  using System.Collections;
  
  public class eastereggscene : MonoBehaviour {
  
      private string[] cheatCode;
      private int index;
  
      void Start()
      {
          // Code is "tilt", user needs to input this in the right order
          cheatCode = new string[] { "t", "i", "l", "t"  };
          index = 0;
      }
  
      void Update()
      {
          // Check if any key is pressed
          if (Input.anyKeyDown)
          {
              // Check if the next key in the code is pressed
              if (Input.GetKeyDown(cheatCode[index]))
              {
                  // Add 1 to index to check the next key in the code
                  index++
             }
              // Wrong key entered, we reset code typing
              else {
                  index = 0;
              }
          }
  
          // If index reaches the length of the cheatCode string, 
          // the entire code was correctly entered
          if (index == cheatCode.Length)
                  Application.LoadLevel(1);
          }

}

There it should be good, but the indentation is not perfect, use Ctrl + K, D to format it properly in VS(I don't know the touches for MonoDevelop).

Hope this do it for you, FireCube

PS: sorry for the last } not into the code block

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fire_Cube · Jul 08, 2016 at 08:03 AM 0
Share

also, try to give a look at the c sharp na$$anonymous$$g convention, it will be easier to other to look at your code

avatar image Zitoox · Jul 08, 2016 at 05:44 PM 0
Share

It still gives me the same error, and Ctrl + $$anonymous$$ + D is not a command in VS 2015 =C

avatar image OrkhanAlikhanov Zitoox · Jul 08, 2016 at 06:17 PM 0
Share

Ctrl + $$anonymous$$, Ctrl + D is not an error fixer it is just shortcut to code formatter.

avatar image Zitoox OrkhanAlikhanov · Jul 08, 2016 at 06:36 PM 0
Share

Look at this alt text

It's not a command, and does nothing

ckd.png (1.8 kB)
Show more comments
avatar image gorsefan · Jul 09, 2016 at 12:08 AM 0
Share

This is correct but the file should end like this:

             if (index == cheatCode.Length) {
                 Application.LoadLevel (1);
             }
         }
     }
 }

:) Add add a semi-colon after index++

avatar image
0

Answer by NAYIR55 · Jul 08, 2016 at 10:27 AM

Hello

Zitoox

I wanted to help too... your curly braces were a total mess, everytime you open anything that has a closing match, you must be sure to close it

  • " " Double quotes

  • ( ) Parenthesis

  • [ ] Square brackets

  • { } Curly braces

  • ' ' Single quote

  • < > Angle brackets

These are the basics in programming

 if (conditional operation inside parenthesis)
              { //Open curly brace
                  conditional body inside curly braces
              } //Close curly brace

Here's your code

 using UnityEngine;
 using System.Collections;
  
  public class eastereggscene : MonoBehaviour 
  {
      private string[] cheatCode;
      private int index;
  
      void Start()
      {
          // Code is "tilt", user needs to input this in the right order
          cheatCode = new string[] { "t", "i", "l", "t"  };
          index = 0;
      }
  
      void Update()
      {
          // Check if any key is pressed
          if (Input.anyKeyDown)
          {
              // Check if the next key in the code is pressed
              if (Input.GetKeyDown(cheatCode[index]))
              {
                  index++
              }
              // Wrong key entered, we reset code typing
              else 
              {
                  index = 0;
              }
          }
  
          // If index reaches the length of the cheatCode string, 
          // the entire code was correctly entered
          if (index == cheatCode.Length)
          {
              Application.LoadLevel(1);
          }
      }
  }

Hope it helps

Cheers

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Zitoox · Jul 08, 2016 at 10:39 PM 0
Share

It still gives me the same error. but different =/

Assets/eastereggscene.cs(25,15): Error CS1525: Unexpected Symbol '}'

avatar image ScaniX · Jul 09, 2016 at 09:41 AM 0
Share

There is a missing ";" after index++ in line 24.

avatar image Zitoox ScaniX · Jul 09, 2016 at 09:08 PM 0
Share

It is correct now. The funny thing is that he said my curly brackets were a total mess and he didn't note that he didn't put a ";" in line 24.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

58 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to activate a function on script B but its called from A 1 Answer

Error scripting message 1 Answer

Script Error 1 Answer

Random: NullReferenceException: Object reference not set to an instance of an object 2 Answers

No suitable method found to override 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges