Hmmā¦ Still no luck with getting the callbacks to fire. Can you think of anything else I should look at?
Hereās the full context of the code:
public class PlayerData : MoralisObject
{
public long TokenCount { get; set; }
public string WalletAddress { get; set; }
public PlayerData() : base("PlayerData") { }
}
private async void Start()
{
var user = await MoralisInterface.GetUserAsync();
if (WalletConnect.Instance.Connected && user != null)
{
setupPlayer(user);
monitorPlayerData();
}
}
private async void setupPlayer(MoralisUser user)
{
var walletAddress = user.authData["moralisEth"]["id"].ToString();
var playerDataQuery = await MoralisInterface.GetClient().Query<PlayerData>();
playerDataQuery = playerDataQuery.WhereEqualTo("WalletAddress", walletAddress);
var queryResult = await playerDataQuery.FindAsync();
PlayerData playerData = queryResult.FirstOrDefault();
if (playerData == null)
{
playerData = MoralisInterface.GetClient().Create<PlayerData>();
playerData.WalletAddress = walletAddress;
playerData.TokenCount = 0;
await playerData.SaveAsync();
}
TokensCollected = playerData.TokenCount;
OnTokenCountChanged?.Invoke(TokensCollected);
}
private async void monitorPlayerData()
{
var query = await MoralisInterface.GetClient().Query<PlayerData>();
MoralisLiveQueryCallbacks<PlayerData> callbacks = new MoralisLiveQueryCallbacks<PlayerData>();
callbacks.OnConnectedEvent += (() => { Console.WriteLine("Connection Established."); });
callbacks.OnSubscribedEvent += ((requestId) => { Console.WriteLine($"Subscription {requestId} created."); });
callbacks.OnUnsubscribedEvent += ((requestId) => { Console.WriteLine($"Unsubscribed from {requestId}."); });
callbacks.OnErrorEvent += ((ErrorMessage em) =>
{
Debug.Log($"***** ERROR: code: {em.code}, msg: {em.error}, requestId: {em.requestId}");
});
callbacks.OnCreateEvent += ((item, requestId) =>
{
Debug.Log($"***** Created");
});
callbacks.OnUpdateEvent += ((item, requestId) =>
{
Debug.Log($"***** Updated");
});
callbacks.OnDeleteEvent += ((item, requestId) =>
{
Debug.Log($"***** Deleted");
});
callbacks.OnGeneralMessageEvent += ((text) =>
{
Debug.Log($"***** Websocket message: {text}");
});
MoralisLiveQueryController.AddSubscription<PlayerData>("PlayerData", query, callbacks);
}