|
Hi guys, I'm sorry if this has been asked and answered before, but I just can't figure this out and my searching has turned up nothing I can get to work in my situation. So my team and I are developing a game for Unity iOS and, as it's essentially a social game, we need to be able to send things back and forth from a server. So, in the scenario we're currently having trouble with we have a log-in form that takes in a number. The number then has to be sent to the server, and the server then has to send back the list of cases (as in a medical case) associated with said number so it can then be parsed from a string stored on the server. This code is called in another class's method upon pressing a log-in button. Really what we want to do is get the data associated with uID and return a string that we can then parse and use in the game. But this doesn't seem to be possible because this is not returning a string. However, it is not possible to yield with a return type of string (or anything not of the iterator interface type). Our current solution was to do a busy-wait loop, which apparently will not work on iOS so we really need some form of a solution that will suit our needs.
(comments are locked)
|
|
You need to yield cases so that the request is processed, then cases.text will contain the return value on the line after the yield. edit WWW is asynchronous so something like this: The to call it: And you need to start the routine with StartCoroutine()
Jun 21 '12 at 06:55 PM
whydoidoit
Like this? Because I tried this and got the UnityException saying "WWW is not ready downloading yet".
Jun 21 '12 at 07:05 PM
fryedrycestyle
No, you've got the wrong idea about coroutines - that isn't going to return you the string - you are going to have to do something when the string arrives later.
Jun 22 '12 at 12:17 AM
whydoidoit
WWW is asynchronous so something like this: The to call it:
Jun 22 '12 at 12:20 AM
whydoidoit
Yes callbacks are a good way to handle such cases. @fryedrycestyle: StartCoroutine will just start the coroutine but returns immediately after the first yield. Unity's coroutine scheduler will take care of resuming it when necessary.
Jun 22 '12 at 12:43 AM
Bunny83
(comments are locked)
|
