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
-2
Question by Raj1v · Apr 30, 2012 at 04:03 PM · not workingif-statement

IF doesn't work

I made a js file to login on my game, but the IF statement doesn't work. And in the debug window i clearly see 'error'

 function Login() {

 var form = new WWWForm(); //here you create a new form connection

 form.AddField( "myform_hash", hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file

 form.AddField( "myform_nick", formNick );

 form.AddField( "myform_pass", formPassword );
 
 var w = WWW("http://sociallife.woelmuis.nl/login.php", form); //here we create a var called 'w' and we sync with our URL and the form

 yield w; //we wait for the form to check the PHP file, so our game dont just hang

 if (w.error != null) {
     print(w.error); //if there is an error, tell us
 } else {
     answer = w.text;
     answer = answer.Replace("<div align=\"center\">","");
     answer = answer.Replace(" ", "");
     status = answer;
     Debug.Log(answer); //here we return the data our PHP told us
     if(answer == "error")
         {
         Debug.Log("loggedin");
         }
     w.Dispose(); //clear our form in game

 }

 

 formNick = ""; //just clean our variables

 formPassword = "";

}

Comment
Add comment · Show 2
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 kolban · Apr 30, 2012 at 04:30 PM 1
Share

Hi there. I think you will have to post more information. What is it about the "if" that doesn't work? What is the nature of the error?

avatar image Raj1v · Apr 30, 2012 at 04:32 PM 0
Share

It doesn't write any 'loggedin' in the debug window. Even the other message in my window clearly says 'error'

3 Replies

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

Answer by perchik · May 09, 2012 at 04:59 AM

So inside the first Else clause, answer is getting set to "error". You then print out answer, and it tells you it is indeed "error". Then you check to see if answer=="error" and it doesn't go into that If statement.

My guess, considering that you are using PHP is that there's some kind of whitespace issue. I see that you are deleting spaces, but that might not mean you're catching all whitespace. Try Debug.Log("|||" + answer + "|||" ) if it doesn't say |||error||| then theres some whitespace you need to trim.

If it does come back as |||error||| then we can go from there.

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 Raj1v · May 09, 2012 at 04:12 PM 0
Share

In the debug line it says |||error . not the last ||| . In the 'extra information' space of the debug window it tells me this "

|||succes varsc_project=7295936; varsc_invisible=1; varsc_security="ee708cde";

||| UnityEngine.Debug:Log(Object) $:$$anonymous$$oveNext() (at Assets/Scripts/LoginGUI.js:73)

"

avatar image perchik · May 09, 2012 at 06:08 PM 0
Share

So you see where the problem is now?
if(answer=="error") comes back false because answer is "error. not the last" which does not equal "error"

Good luck handling that!

avatar image Raj1v · May 09, 2012 at 07:07 PM 0
Share

I fixed it using String.contains()

avatar image
-1

Answer by -hiTo- · May 01, 2012 at 12:49 PM

I don't really understand your problem... If you get an error message from your WWW-object, it should say "Error" in your debug window. You yourself has made it so:

 if (w.error != null) {
     print(w.error); //if there is an error, tell us
 }

This just tells me there is something wrong along the way. Either you're giving the wrong address or a connection could not be made, or something along those lines. But we will never know if you don't tell us what the error says and on which line, etc.

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 Raj1v · May 01, 2012 at 02:48 PM 0
Share

No, it is a login script. If i use the wrong login info it shows error in the debug window, but when i fill in correct info it properly shows 'success' but when I use if to check what it returned it doesn't work.

avatar image -hiTo- · May 09, 2012 at 02:21 AM 0
Share

Are you telling me that Debug.Log(answer); prints "success" and that the following if-statement doesn't fire? That would be because the if-statement will only fire if 'answer' is "error", not "success". Otherwise I'm still having trouble understanding your problem. You need to tell us WHICH if-statement does not work, and WHAT prints "success" and WHEN you want this if-statement to fire.

avatar image
0

Answer by mrldev · May 09, 2012 at 06:14 PM

What if it can process the if directive, jumps to the else directive and finds it cannot do what it is supposed to. It would not return anything. Add another step. Perhaps turn the else into an else if and then add the else for if both fail.

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

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

8 People are following this question.

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

Related Questions

How to control the movements of an object in Unity with Neurosky? 0 Answers

Extremely Buggy rigidbody collisions [URGENT, DEADLINE 3 DAYS AGO!!!!!!! C#] Please answer. I can't figure it out! (As of 1 Answer) 2 Answers

facebook Login Script user_about_me, user_birthday", AuthCallback ??? not working! 0 Answers

Unet Not Syncing Health for Host 1 Answer

Array not working as expected 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