❔ async await nooob trying to do the simplest of simple await for a string to be returned?
This is my Client code:
Await server to give name to client after request:
This is client code aswell, which is called by ChatSystem for example:
36 Replies
I guess for start should be
GetNameAsync(long id)
? So we actually know whuch ID to wait for? - EDIT: I fixed that partthis can't be made async unless
CommsManager.Instance.CMD_RequestName(id)
is made asyncBut CommsManager uses ServerRPC which runs code on Server only and cant return anything, so I think its impossible?
¯\_(ツ)_/¯
I think you need to google very specifically about whatever RPC framework this is, and how to use async properly with it
I know the namespace and server class should have different name and it looks like it was coded by shrek
this is some unity stuff, I assume?
Yes FishNetwork for Unity
yeah, you'll need to check their docs
ServerRPC cant return anything, and they never tested async ServerRPC but asked me to test it
there is no silver bullet answer here
But if ServerRPC cant return anything then async is impossible i think?
¯\_(ツ)_/¯
(╯°□°)╯︵ ┻━┻
how does your code get the name, if the RPC call cant return anything?
TargetRPC
oh it RPCs back.. fuck thats so gnarly
sends the name to specific connection, in this case the connection that requested it
you'll need to build your own statemachine around that most likely
oof fug
I will just use callback lmao
FishNetwork is 100% callbacks internally aswell
so probably for a good reason
I guess ill add another gnarly callback so it just works
thanks for your time
Is this possible @Pobiega ? (sorry for ping)
?
no
a method cant get its returnvalue from another method
(thats called remotely lol)
So I need to store ID, and when name is received, check for stored IDs that were waiting and then return the name somehow
yes
you could have your "GetName" method poll the place where names get put
like, check for answer, wait 1ms, try again
Hmm I can use async await for that?
Task.Delay(10) or something?
sure
ok ok ill try
thanks again!
This all happens inside the
UI_Chat
class, which is a Client-only class for displaying chat messages.
EDIT: Changed to TryGetName - new method which doesnt request from server the name 600 times lol, it just checks if its arrived
Or is this wetarded, i have no idea, i never used async await before tbh
i mean i wrote it once without any errors in console but it turned out to be useless for that use case anyway and that was a few months agouhm
also UniTask == Task, its literally the same, only it works within Uity, which normal Tasks do not
doesnt
ClientNamingSystem.GetName(NamingSystemType.CharacterName, senderID)
send the RPC request?yes
you only want to run that once, not in the loop
yes you are correct
i will make a new method that only checks if its there and doesnt request again
alr im gonna check out at this point, fever is spiking so I cant even think straight
good luck
Thanks and get well soon!
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.