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
1
Question by Catlard · May 27, 2011 at 12:52 AM · comparecharactersstring comparisoncompare-string

String comparison weirdness.

Howdy!

So, I'm building a game which tests ESL students by asking them to type the names of fruits written on virtual placards. And I'm attempting to implement a system where they can type something, have it appear on screen, and if it's the correct spelling, then it will automatically cause that fruit to fly off the screen. This works if the fruit's name is the first and only thing you type. But if you delete what you've typed (assuming a scenario where one makes a typing error), it doesn't register the two strings as equal. I've tested these two strings at runtime (see commented out flag print statements), and Unity says they're equal. So I'm way confused. Even though characterchecker.answer, the string that fruit is looking for in order to fly away is identical to typed_string, it's not registering them as equal.

Perhaps there's something subtle about strings I don't understand? I'll give a more accurate description of the error, and show you the classes where i am pretty darn sure the error lies.

I'd be much obliged and sing praises of your heroic deeds to my descendants, if you could help me out on this one. Thanks so much for your time!

--Simon

ERROR: WHEN INPUT_STRING ONCE AGAIN

SCRIPT: CHARACTER DESTROYER. THIS SCRIPT COMPARES THE NAMES OF ALL THE FRUITS ON SCREEN, THEIR VARIABLE CALLED MYTARGET.ANSWER, TO THE STRING OF CHARACTERS THAT THE USER HAS TYPED IN, CALLED TYPED_STRING. I'VE EMBOLDENED WHERE IT CHECKS FOR THIS EQUALITY.

private var mytarget; var characterchecker; var perspectivescript; var mydistance; var placards_onscreen = 1; var time_between_waves = 2.00; private var placards_active = placards_onscreen; var musicplacer: GameObject; var placardplacer: GameObject; var callednewplacards = false; var combocount = 0; var mistake_count = 0; var eyeofbeholder: GameObject; var guiscript; guiscript = eyeofbeholder.GetComponent("Basic GUI"); var numberdestroyed = 0; var missed_answer = "";

function Start() { CallNewPlacards(); }

function Update() { //print("This Frame's Variables:"); //print("-----------------------"); //print("Typed String: " + guiscript.typed_string); //print("Initial String: " + guiscript.initial_string); //print("Input String: " + Input.inputString); if(Input.GetKeyDown("backspace")) { guiscript.typed_string = ""; } if(Input.anyKeyDown && GameObject.FindGameObjectsWithTag("Ground Placards").length) { eyeofbeholder.SendMessage("AddCharToString", Input.inputString); TestClosestPlacard(); ResetPlacardTags(); } placards_active = GameObject.FindGameObjectsWithTag("Ground Placards").length; if(!placards_active && !callednewplacards) { Invoke("CallNewPlacards", time_between_waves); callednewplacards = true; } }

function TestClosestPlacard() { mytarget = FindClosestPlacard(); if(mytarget != null) { characterchecker = mytarget.GetComponent("Character Checker"); perspectivescript = mytarget.GetComponent("Perspective Cheater"); if(guiscript.typed_string != characterchecker.answer && mydistance<1600) { mytarget.tag = "Already Looked"; TestClosestPlacard(); } print("Typed:" + guiscript.typed_string); print("Answer:" + characterchecker.answer); print("can knock down:" + perspectivescript.canknockdown); if((characterchecker.answer == guiscript.typed_string) && perspectivescript.canknockdown && !characterchecker.destroyit) { characterchecker.destroyit = true; mytarget.tag = "Destroyed Placards"; combocount++; guiscript.typed_string = ""; numberdestroyed++; }

 }

}

// Find the name of the closest enemy function FindClosestPlacard () : GameObject { // Find all game objects with tag Enemy var gos : GameObject[]; gos = GameObject.FindGameObjectsWithTag("Ground Placards"); var closest : GameObject; mydistance = Mathf.Infinity; var myposition = transform.position; // Iterate through them and find the closest one for (var go : GameObject in gos)
{ var diff = (go.transform.position - myposition); var curDistance = diff.sqrMagnitude; if (curDistance < mydistance) { closest = go; mydistance = curDistance; } } return closest;
}

function ResetPlacardTags() { var allplacards = GameObject.FindGameObjectsWithTag("Already Looked"); for (var placard: GameObject in allplacards) { placard.tag = "Ground Placards"; } }

function CallNewPlacards() { for(var i: int = 0; i < placards_onscreen; i++) { placardplacer.SendMessage ("SetNewPlacard"); } placards_active = placards_onscreen; callednewplacards = false; }

Comment
Add comment
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

3 Replies

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

Answer by Catlard · May 27, 2011 at 01:01 AM

Shoot. I'm going to answer my own question. I deleted the string, and then tried to add a character to it with that sendmessage.

Does this mean I get a darwin award? Or whatever award they give to the teddy bear sitting at the booth where you can explain your bug to it?

Thanks, Unity Answers! You're my teddy bear.

Comment
Add comment · 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
2

Answer by testure · May 27, 2011 at 02:29 AM

In the future, use the code tags when pasting in blocks of code- nobody is going to read that mess :)

Comment
Add comment · 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
0

Answer by Catlard · May 27, 2011 at 02:50 AM

Ok. Thanks. I wasn't sure they had any here. I'll look it up.

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 Eric5h5 · May 27, 2011 at 02:51 AM 0
Share

Also, don't post comments as answers.

avatar image Joshua · May 27, 2011 at 03:03 AM 1
Share

Be nice, he's obviously new, so welcome! To wrap your code in tags select it and press the button that says 101 on top and 010 underneath that.

avatar image Catlard · May 27, 2011 at 03:06 AM 0
Share

Ok, cheeers, I didn't know the difference between the two. Will do that in the future. Thanks for being friendly, everybody!

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I find which string comes first alphabetically? 1 Answer

object.ToString never equals the string 2 Answers

Sort Multiple Arrays By Their Length 1 Answer

Find the differences between two lists 1 Answer

error CS0019: Operator `<=' cannot be applied to operands of type `UnityEngine.Vector3' and `float' 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