Carly.TeamSail
Carly.TeamSail
CC#
Created by Carly.TeamSail on 10/25/2023 in #help
❔ async await nooob trying to do the simplest of simple await for a string to be returned?
This is my Client code:
public static string GetName(NamingSystemType type, long id)
{
if (names.TryGetValue(type, out Dictionary<long, string> dict))
{
if (dict.TryGetValue(id, out string name)) return name;
else
{
CommsManager.Instance.CMD_RequestName(id);
return "";
}
}
else return "";
}
public static void AddName(NamingSystemType type, long id, string addingName)
{
if (!names.TryGetValue(type, out Dictionary<long, string> dict))
{
names.Add(type, dict = new Dictionary<long, string>());
}
if (dict.TryGetValue(id, out string name))
{
return;
}
else dict.Add(id, addingName);
}
public static string GetName(NamingSystemType type, long id)
{
if (names.TryGetValue(type, out Dictionary<long, string> dict))
{
if (dict.TryGetValue(id, out string name)) return name;
else
{
CommsManager.Instance.CMD_RequestName(id);
return "";
}
}
else return "";
}
public static void AddName(NamingSystemType type, long id, string addingName)
{
if (!names.TryGetValue(type, out Dictionary<long, string> dict))
{
names.Add(type, dict = new Dictionary<long, string>());
}
if (dict.TryGetValue(id, out string name))
{
return;
}
else dict.Add(id, addingName);
}
Await server to give name to client after request: This is client code aswell, which is called by ChatSystem for example:
internal static Task<string> GetNameAsync(long id)
{
// while(waitingForNameToBeAdded)??
How do I wait for server to addName as seen above?
}
internal static Task<string> GetNameAsync(long id)
{
// while(waitingForNameToBeAdded)??
How do I wait for server to addName as seen above?
}
56 replies
CC#
Created by Carly.TeamSail on 10/22/2023 in #help
❔ EntityFramework - How do I figure out what ORM expects?
#region Assembly AgeOfSailOnline_DB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// AgeOfSailOnline_DB.dll
#endregion

#nullable enable

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AgeOfSailOnline_DB.Entities
{
[Table("accounts", Schema = "main")]
public class AccountEntity
{
public AccountEntity();

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public long AccountID { get; }
public string Email { get; set; }
public string Salt { get; set; }
public string Verifier { get; set; }
public DateTime Created_At { get; set; }
public bool Banned { get; set; }
public bool IsGameMaster { get; set; }
}
}
#region Assembly AgeOfSailOnline_DB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// AgeOfSailOnline_DB.dll
#endregion

#nullable enable

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AgeOfSailOnline_DB.Entities
{
[Table("accounts", Schema = "main")]
public class AccountEntity
{
public AccountEntity();

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Key]
public long AccountID { get; }
public string Email { get; set; }
public string Salt { get; set; }
public string Verifier { get; set; }
public DateTime Created_At { get; set; }
public bool Banned { get; set; }
public bool IsGameMaster { get; set; }
}
}
I get an error:
No account.account_id found.
So I changed my DB table from accountid to account_id. Now it works as expected. but how do i know in advance what the Database expects? This is EF Core related according to PostgreSQL devs (my DB provider). For example right now EF Core also expects is_game_master but i want it to just be gm Thanks for your time! Ok
16 replies
CC#
Created by Carly.TeamSail on 10/16/2023 in #help
❔ EntityFramework - Need help setting up/creating my first VS Community .NET 2.1 Project
No description
137 replies
CC#
Created by Carly.TeamSail on 10/14/2023 in #help
❔ UniTask / Unity - await/async connoisseurs wanted. Need help understanding
public void TryRegister()
{
TryRegisterAsync().Forget(); // UI Register Button - Fire & Forget Method,
}
public async UniTaskVoid TryRegisterAsync()
{
PlayerSelectionData[] psd = await tryRegisterAsync();

UI_PlayerSelection.Instance.Init(psd);
gameObject.SetActive(false);
}
private async UniTask<PlayerSelectionData[]> tryRegisterAsync()
{
var email = _emailInput.text;
var pass = _passwordInput.text;

PlayerSelectionData[] psd = await CommsManager.Instance.CMD_TryRegisterAsync(email, pass);

return psd;
}
public void TryRegister()
{
TryRegisterAsync().Forget(); // UI Register Button - Fire & Forget Method,
}
public async UniTaskVoid TryRegisterAsync()
{
PlayerSelectionData[] psd = await tryRegisterAsync();

UI_PlayerSelection.Instance.Init(psd);
gameObject.SetActive(false);
}
private async UniTask<PlayerSelectionData[]> tryRegisterAsync()
{
var email = _emailInput.text;
var pass = _passwordInput.text;

PlayerSelectionData[] psd = await CommsManager.Instance.CMD_TryRegisterAsync(email, pass);

return psd;
}
Is this correct? I want to wait for Server (via CommsManager) to reply with PlayerSelectionData[], after receiving that, I want to call UI_PlayerSelection.Instance.Init(psd); BTW, UniTask is pretty much the same as C# Tasks, just a different keyword for example async void == async UniTaskVoid. CommsManager (method just for testing):
public async UniTask<PlayerSelectionData[]> CMD_TryRegisterAsync(string email, string pass)
{
await UniTask.Delay(1000);

var psd1 = new PlayerSelectionData("Player_1", 3);
var psd2 = new PlayerSelectionData("Player_2", 10);
return new PlayerSelectionData[] { psd1, psd2 };
}
public async UniTask<PlayerSelectionData[]> CMD_TryRegisterAsync(string email, string pass)
{
await UniTask.Delay(1000);

var psd1 = new PlayerSelectionData("Player_1", 3);
var psd2 = new PlayerSelectionData("Player_2", 10);
return new PlayerSelectionData[] { psd1, psd2 };
}
This seems to work... But I heard its incorrect, see replies below. Thanks
114 replies