Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 KalteWasser29 · Jul 21, 2012 at 11:46 PM · stringifelsecase

if,if,if, string cases, and if not, then something else?

I've added chat emotes, and commands to my chat, but how do I check for several cases of inputs, and if none of them just do a normal one. e.g.

If /dance Then....

If /Smile Then...

And in the end, if nothing of the ones above, then do normal text. How do I do this context of many if cases, or could I use a wild card, to check if first character of the string is a "/" .. Cutout from the code (.js):

 if(inputField == "/smile")
 {
 inputField = "ARRRRRRRRRRRRRRRGH SMILE!";
 }
  
 else
 { 
 // Normal chat output would go here. 
 }
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 KalteWasser29 · Jul 21, 2012 at 10:44 PM 0
Share

I could make an If (.. || .. || .. || .. || .. ) then find out what one it was, else do normal. But there must be an easier way, like to check if the string starts with / or not?

1 Reply

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

Answer by AlucardJay · Jul 21, 2012 at 11:56 PM

Use a Switch-Case :

  private var inputField : String = "/smile";

  switch(inputField )
  {
      case "/smile" :
          // do stuff for condition 1
          outputField = "ARRRRRRRRRRRRRRRGH SMILE!";
      break;
 
      case "/frown" :
          // do stuff for condition 2
          outputField = "why so down?";
      break;
 
      case "/angry" :
          // do stuff for condition 3
          outputField = "Look Out";
      break;
 
      default :
          // do stuff if none of the above
          outputField = "Nice Day !";
      break;
  }
Comment
Add comment · Show 2 · 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 AlucardJay · Jul 22, 2012 at 12:05 AM 0
Share

Note: I havn't used this with strings, so if you have any probs, create an array of strings and just have each case as a reference to that array i.e. var inputEmotes : String[3]; then case inputEmotes[0]: case inputEmotes[1]: etc. let me know and I shall submit a tested working script.

avatar image KalteWasser29 · Jul 22, 2012 at 11:31 AM 0
Share

Also working on this project, and the string code worked, including the style colouring for emotes, thank you.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Using the StartsWith function in a Switch Case Statement 1 Answer

if a string has certain letter(s) or number(s) 2 Answers

Keeps returning True 2 Answers

How stop a piece of code from running if the conditions are no more met. 1 Answer

Button if else statement? 1 Answer


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