Unity Subscribe to Events code examples need changes.
On the Unity Getting Started (https://dev.twitch.tv/docs/game-engine-plugins/unity-guide/) page, under Subscribe to Events, the examples might be a bit inaccurate. Here is the code for Channel Point Rewards:
GameTask<EventStream<CustomRewardEvent>> CustomRewardEvents;
start()
{
CustomRewardEvents = SubscribeToCustomRewardEvents();
}
update()
{
var CurRewardEvent;
CustomRewardEvents.TryGetNextEvent(out CurRewardEvent);
if(CurRewardEvent != null)
{
//Do something
Debug.Log("{CurRewardEvent.RedeemerName} has brought {CurRewardEvent.CustomRewardTitle} for {CurRewardEvent.CustomRewardCost}!");
}
}
Issues:
- void Start(), void Update().
- SubscribeToCustomRewardEvents() is a member of 'Twitch.API'. So it should be 'Twitch.API.SubscribeToCustomRewardEvents()'.
- 'var' variables are implicitely typed, so the line 'var CurRewardEvent;' throws an erorr. 'CustomRewardEvent CurRewardEvent;' would work.
- CustomRewardEvents task doesn't have TrgGetNextEvent() or WaitForEvent() methods. To access those methods you have to use 'CustomRewardEvents.MaybeResult'. So it should be 'CustomRewardEvents.MaybeResult.TryGetNextEvent()'.
These issues are present in the Follows, Subscribers, HypeTrain and Raids code examples a well.