- Home /
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 )
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.
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.
@Dave Carlile,
if (perm2.ToString() == "photo_upload")
Did the trick. If you post it in the answer, I'll select it.
Posted. Did you try the foreach (string perm2...) thing? I guess I'm old school and prefer to be explicit about my data types.
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")...
Answer by CheaterXman · Mar 06, 2013 at 08:16 PM
Are you sure the script is starting? Is it a container on a Empty?
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?
Your answer
![](https://koobas.hobune.stream/wayback/20220613093938im_/https://answers.unity.com/themes/thub/images/avi.jpg)