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 infinitypbr · Mar 06, 2013 at 06:17 PM · c#if-statements

Why is this simple C# script not working?

[I have asked Prime31, and they only replied that the return is indeed a string, offering no other information]

Using Prime31s Social Networking iOS Plugin -- I can confirm that permissions ARE granted (and in fact the script's debug log shows the same). The problem is that the script doesn't seem to be triggering the part that sets my variables to true. I can't seem to figure out why. Granted I'm new to C#, so it could just be a dumb mistake.

The Code:

 IEnumerator CheckPermissions()
     {
         while (!canPublishStream || !canPhotoUpload)
         {
             var permissions2 = FacebookBinding.getSessionPermissions();
             foreach( var perm2 in permissions2 )
             {
                 if (perm2 == "publish_stream")
                 {
                     canPublishStream = true;    
                 }
                 if (perm2 == "photo_upload")
                 {
                     canPhotoUpload = true;    
                 }
                 print ("A permission2: " + perm2 + " ( " + canPublishStream + " / " + canPhotoUpload + " )");
             }
             yield return new WaitForSeconds(5);
         }    
     }

XCode provides a slew of information, showing I have permission for a bunch of stuff. However, the results below show what confuses me: that perm2 sure does equal the variable (publish_stream) or (photo_upload), but the true statements were not triggered.

A permission2: photo_upload ( False / False )

Comment
Add comment · Show 4
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 Dave-Carlile · Mar 06, 2013 at 06:51 PM 0
Share

I'm wondering if perm2 isn't actually a string data type? I know you say you confirmed that, but maybe they were confused about what you were asking. Try this...

 foreach (string perm2 in permissions2)
 {
   // your if statements here
 }

or

 if (perm2.ToString() == "photo_upload")...


Otherwise yeah, this seems really weird.

avatar image PAEvenson · Mar 06, 2013 at 06:52 PM 0
Share

have you tried logging inside the if statements to see if they are actually getting set? Your code looks like it should work fine to me.

avatar image infinitypbr · Mar 06, 2013 at 07:24 PM 0
Share

@Dave Carlile,

if (perm2.ToString() == "photo_upload")

Did the trick. If you post it in the answer, I'll select it.

avatar image Dave-Carlile · Mar 06, 2013 at 09:03 PM 0
Share

Posted. Did you try the foreach (string perm2...) thing? I guess I'm old school and prefer to be explicit about my data types.

3 Replies

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

Answer by Dave-Carlile · Mar 06, 2013 at 09:02 PM

I'm wondering if perm2 isn't actually a string data type? I know you say you confirmed that, but maybe they were confused about what you were asking. Try this...

 foreach (string perm2 in permissions2)
 {
   // your if statements here
 }

or

 if (perm2.ToString() == "photo_upload")...
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 CheaterXman · Mar 06, 2013 at 08:16 PM

Are you sure the script is starting? Is it a container on a Empty?

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 Bunny83 · Mar 06, 2013 at 07:42 PM

You said that perm2 really contains "photo_upload", but how did you check if that's really true? There could be a line break, a space, maybe a null character in the string. Add this at the end of your print statement:

     + " L:" + perm2.Length);

It should give you "L:12" for "photo_upload" and "L:14" for "publish_stream". If not the string is not equal.

To fix this you chould try adding something like this inside your for-loop:

     perm2 = perm2.Trim().ToLower();

Of course before you do your if statements ;)

ps: I'm just wondering, when none of the bool variables turn true you should see the print every 5 sec, right?

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

14 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Use a #if statement to check if a script exists in project? 0 Answers

C# Declaring Variables Within If Statements 2 Answers

Do I need to explicitly test for null or is testing the object itself good enough? 2 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