Hi there,
This is less to do with Unity as much as C#, but hopefully someone can help.
I am using a plugin and have this line onEnable(){}
TwitterManager.loginSucceededEvent += loginSucceeded;
What I am wondering is, what does the “+=” represent in this case?
Thanks
loginSucceededEvent is an ‘event’.
Events are special types of delegates that can only be invoked by the class that declares the event.
The += adds a function delegate to the list of delegates that will be called by the TwitterManager… I suspect when a login request succeeds. So when that occurs, your function ‘loginSucceeded’ will get called.
Check out here for information on events:
Thank you,
yes, I just looked it up.
Quick related question.
I have a script, Twitter_Controller, which uses a pointer, TwitterBinding. This script was made by a professional, so all should be good. However, when not //blanked out, I recieve an error that the TwitterBinding does not exist.
I do have a script, also part of the professional package called TwitterBinding.
Would you have any suspicions as to why the Twitter_Controller using the pointer TwitterBinding, is somehow not seen by Unity? I have moved scripts from plug ins folder to script folders etc. but with no luck.
Thanks if you have any idea what I am talking about.
What do you mean by a “pointer”? Is it a member variable of some other class? Is it referring to a class itself?
Well,
Script A…
Is calling functions in the TwitterBinding class via (what I would call a pointer)
TwitterBinding.someEvent += someValue;
Double check if both are using the same and not different languages or whether it’s platform specific which would only appear if you have the target platform to iOS for example
Both are C#.
The Twitter_Controller script, the source of the error, where unity does not recognize its call to TwitterBinding… Has no reference to iOS or Android.
The TwitterBinding script, does use if iOS, specifically,
#ifUNITY_IPHONE
My player settings are set iOS platform.
?? And thanks.
that #if needs a space
I can’t help you further unless I see more code.
Thanks,
The space is there.
I must have deleted in here.
TwitterBinding
Twitter Controller
edit.
could it be a version issue? Either this plug in or Unity?
TwitterBinding is in the Prime31 namespace which you haven’t included in your controller.
1 Like
I’ve noticed that pasting from MonoDevelop sometimes removes spaces. Are you on Mac? Try “Paste and Match Style” instead of a standard paste, I think that’s what worked for me.
As for your mystery pointer - that’s a class. There are two reasons that come to mind that might explain why their class can see TwitterBinding and yours can’t:
- Theirs is in a later phase of compilation than yours. Unlikely, because if they’re both C#, that would basically means that theirs is an Editor script.
- TwitterBinding is in a namespace which the class referencing it is using. Far more likely.
So in the script that references TwitterBinding, check to see if either their class is surrounded by “namespace SomeNamespace { public class … }”, or if they have a conspicuous-looking “using SomeNamespace;” directive at the top. In either case, you should be able to get ahold of it via “SomeNamespace.TwitterBinding”.
…and if that doesn’t work, I am very curious indeed.
Edit: As @KelsoMRK pointed out, the namespace you’re looking for is Prime31. Hopefully my answer provides information you can use in this sort of situation in the future, though.
Excellent,
I am sure that is it.
Thank you.
Just learning Event programming now.
Cheers
ya once you learn it, it will really change the way you approach certain problems. Lets you decouple and abstract things a lot more as well making for more reusable code.
there its also lots of good information here, if you want to be able assign listners to events via the inspector by using UnityEvents and UnityActions
http://forum.unity3d.com/threads/unityevent-where-have-you-been-all-my-life.321103/page-2#post-2098451